blob: a50f1fec885d86643cc8ae96ded5088beff63665 [file] [log] [blame]
Christopher Fauletc5a0aee2020-02-05 16:46:38 +01001varnishtest "Test the HTTP return action"
2#REQUIRE_VERSION=2.2
3
4# This config tests the HTTP return action.
5
6feature ignore_unknown_macro
7
8haproxy h1 -conf {
9 defaults
10 mode http
11 timeout connect 1s
12 timeout client 1s
13 timeout server 1s
14
15 frontend fe1
16 bind "fd@${fe1}"
17 http-request return if { path /def-1 }
18 http-request return hdr "x-custom-hdr" "%[url]" if { path /def-2 }
19 http-request return status 403 if { path /def-3 }
20 http-request return content-type "text/plain" if { path /def-4 }
21
22 http-request return content-type "text/plain" string "hello" hdr "x-custom-hdr" "%[url]" if { path /string }
23 http-request return content-type "text/plain" lf-string "path is %[url]" hdr "x-custom-hdr" "%[url]" if { path /lf-string }
24 http-request return content-type "text/plain" file /dev/null hdr "x-custom-hdr" "%[url]" if { path /empty-file }
25 http-request return content-type "text/plain" file ${testdir}/1k.txt hdr "x-custom-hdr" "%[url]" if { path /file }
26 http-request return content-type "text/plain" lf-file ${testdir}/lf-file.txt hdr "x-custom-hdr" "%[url]" if { path /lf-file }
27} -start
28
29client c1 -connect ${h1_fe1_sock} {
30 txreq -req GET -url /def-1
31 rxresp
32 expect resp.status == 200
33 expect resp.http.content-length == 0
34 expect resp.http.content-type == <undef>
35 expect resp.http.x-custom-hdr == <undef>
36
37 txreq -req GET -url /def-2
38 rxresp
39 expect resp.status == 200
40 expect resp.http.content-length == 0
41 expect resp.http.content-type == <undef>
42 expect resp.http.x-custom-hdr == "/def-2"
43
44 txreq -req GET -url /def-3
45 rxresp
46 expect resp.status == 403
47 expect resp.http.content-length == 0
48 expect resp.http.content-type == <undef>
49
50 txreq -req GET -url /def-4
51 rxresp
52 expect resp.status == 200
53 expect resp.http.content-length == 0
54 expect resp.http.content-type == <undef>
55
56 txreq -req GET -url /string
57 rxresp
58 expect resp.status == 200
59 expect resp.http.content-length == 5
60 expect resp.http.content-type == "text/plain"
61 expect resp.http.x-custom-hdr == "/string"
62 expect resp.body == "hello"
63
64 txreq -req GET -url /lf-string
65 rxresp
66 expect resp.status == 200
67 expect resp.http.content-length == 18
68 expect resp.http.content-type == "text/plain"
69 expect resp.http.x-custom-hdr == "/lf-string"
70 expect resp.body == "path is /lf-string"
71
72 txreq -req GET -url /empty-file
73 rxresp
74 expect resp.status == 200
75 expect resp.http.content-length == 0
76 expect resp.http.content-type == <undef>
77 expect resp.http.x-custom-hdr == "/empty-file"
78
79 txreq -req GET -url /file
80 rxresp
81 expect resp.status == 200
82 expect resp.http.content-length == 1024
83 expect resp.http.content-type == "text/plain"
84 expect resp.http.x-custom-hdr == "/file"
85
86 txreq -req GET -url /lf-file
87 rxresp
88 expect resp.status == 200
89 expect resp.http.content-length == 17
90 expect resp.http.content-type == "text/plain"
91 expect resp.http.x-custom-hdr == "/lf-file"
92 expect resp.body == "path is /lf-file\n"
93} -run