blob: b03f2ace70638568d1dedb556a917284ba8eae8c [file] [log] [blame]
Christopher Faulet3b967c12020-05-15 15:47:44 +02001varnishtest "Test the http-error directive"
2#REQUIRE_VERSION=2.2
3
4# This config tests the http-error directive.
5
6feature ignore_unknown_macro
7
8
9haproxy h1 -conf {
10 http-errors errors-1
11 errorfile 400 ${testdir}/errors/400-1.http
12 errorfile 403 ${testdir}/errors/403-1.http
13 errorfile 404 ${testdir}/errors/404-1.http
14 errorfile 500 ${testdir}/errors/500-1.http
15
16 defaults
17 mode http
18 timeout connect 1s
19 timeout client 1s
20 timeout server 1s
21 errorfile 400 ${testdir}/errors/400.http
22 errorfile 404 ${testdir}/errors/404.http
23
24 frontend fe1
25 bind "fd@${fe1}"
26
27 http-error status 400
28 http-error status 403 default-errorfiles
29 http-error status 404 errorfiles errors-1
30 http-error status 500 errorfile ${testdir}/errors/500.http
31 http-error status 200 content-type "text/plain" hdr x-path "path=%[path]" lf-string "The path is \"%[path]\""
32
33 http-request return status 200 default-errorfiles if { path /200 }
34 http-request deny deny_status 400 if { path /400 }
35 http-request deny deny_status 403 if { path /403 }
36 http-request deny deny_status 404 if { path /404 }
37 http-request deny deny_status 500 if { path /500 }
38
39} -start
40
41client c1r1 -connect ${h1_fe1_sock} {
42 txreq -req GET -url /200
43 rxresp
44 expect resp.status == 200
45 expect resp.http.x-path == "path=/200"
46 expect resp.http.content-type == "text/plain"
47 expect resp.body == "The path is \"/200\""
48} -run
49client c1r2 -connect ${h1_fe1_sock} {
50 txreq -req GET -url /400
51 rxresp
52 expect resp.status == 400
53 expect resp.http.x-err-type == <undef>
54 expect resp.http.content-length == 0
55} -run
56client c1r3 -connect ${h1_fe1_sock} {
57 txreq -req GET -url /403
58 rxresp
59 expect resp.status == 403
60 expect resp.http.x-err-type == <undef>
61 expect resp.http.content-length == 93
62 expect resp.http.content-type == "text/html"
63} -run
64client c1r3 -connect ${h1_fe1_sock} {
65 txreq -req GET -url /404
66 rxresp
67 expect resp.status == 404
68 expect resp.http.x-err-type == "errors-1"
69} -run
70client c1r4 -connect ${h1_fe1_sock} {
71 txreq -req GET -url /500
72 rxresp
73 expect resp.status == 500
74 expect resp.http.x-err-type == "default"
75} -run