blob: 78af4472178ff1aa3e7e4608a4e9974c9b998375 [file] [log] [blame]
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +02001#commit 271022150d7961b9aa39dbfd88e0c6a4bc48c3ee
2# BUG/MINOR: map: fix map_regm with backref
3#
4# Due to a cascade of get_trash_chunk calls the sample is
5# corrupted when we want to read it.
6#
7# The fix consist to use a temporary chunk to copy the sample
8# value and use it.
9
10varnishtest "map_regm get_trash_chunk test"
11feature ignore_unknown_macro
12
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +010013#REGTEST_TYPE=bug
14
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020015syslog S1 -level notice {
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020016 recv info
17 # not expecting ${h1_pid} with master-worker
18 expect ~ "[^:\\[ ]\\[[[:digit:]]+\\]: .* fe1 be1/s1 [[:digit:]]+/[[:digit:]]+/[[:digit:]]+/[[:digit:]]+/[[:digit:]]+ 200 [[:digit:]]+ - - ---- .* \"GET / HTTP/(1|2)(\\.1)?\""
19} -start
20
21server s1 {
22 rxreq
23 expect req.method == "GET"
24 expect req.http.x-mapped-from-header == example_AND_org
25 expect req.http.x-mapped-from-var == example_AND_org
26 txresp
27
28 rxreq
29 expect req.method == "GET"
30 expect req.http.x-mapped-from-header == www.example_AND_org
31 expect req.http.x-mapped-from-var == www.example_AND_org
32 txresp
33} -start
34
35haproxy h1 -conf {
36 global
37 log ${S1_addr}:${S1_port} local0 debug err
38
39 defaults
40 mode http
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020041 log global
42 option httplog
Willy Tarreaudb522b52020-09-02 07:26:08 +020043 timeout connect 1s
44 timeout client 1s
45 timeout server 1s
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020046
47 frontend fe1
48 bind "fd@${fe1}"
49 # Remove port from Host header
50 http-request replace-value Host '(.*):.*' '\1'
51 # Store host header in variable
52 http-request set-var(txn.host) req.hdr(Host)
53 # This works correctly
Frédéric Lécailleb894f922019-03-29 16:13:48 +010054 http-request set-header X-Mapped-From-Header %[req.hdr(Host),map_regm(${testdir}/map_regm_with_backref.map,"unknown")]
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020055 # This breaks before commit 271022150d7961b9aa39dbfd88e0c6a4bc48c3ee
Frédéric Lécailleb894f922019-03-29 16:13:48 +010056 http-request set-header X-Mapped-From-Var %[var(txn.host),map_regm(${testdir}/map_regm_with_backref.map,"unknown")]
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020057
58 default_backend be1
59
60 backend be1
61 server s1 ${s1_addr}:${s1_port}
62} -start
63
64client c1 -connect ${h1_fe1_sock} {
65 txreq -hdr "Host: example.org:8443"
66 rxresp
67 expect resp.status == 200
68
69 txreq -hdr "Host: www.example.org"
70 rxresp
71 expect resp.status == 200
72} -run
73