fix relay "append header" action, add regression test for append
authorbenno <benno@openbsd.org>
Sat, 12 Jul 2014 15:47:18 +0000 (15:47 +0000)
committerbenno <benno@openbsd.org>
Sat, 12 Jul 2014 15:47:18 +0000 (15:47 +0000)
ok reyk

regress/usr.sbin/relayd/args-http-append-header.pl [new file with mode: 0644]
usr.sbin/relayd/relay_http.c

diff --git a/regress/usr.sbin/relayd/args-http-append-header.pl b/regress/usr.sbin/relayd/args-http-append-header.pl
new file mode 100644 (file)
index 0000000..f734445
--- /dev/null
@@ -0,0 +1,40 @@
+# test appending headers, both directions
+
+use strict;
+use warnings;
+
+my %header_client = (
+       "X-Header-Client" => "ABC",
+);
+my %header_server = (
+       "X-Header-Server" => "XYZ",
+);
+our %args = (
+    client => {
+       func => \&http_client,
+       header => \%header_client,
+       loggrep => {
+           "X-Header-Server: XYZ" => 1,
+           "X-Header-Server: xyz" => 1,
+       },
+    },
+    relayd => {
+       protocol => [ "http",
+           'match request header append "X-Header-Client" value "abc"',
+           'match response header append "X-Header-Server" value "xyz"',
+           'match request header log "X-Header*"',
+           'match response header log "X-Header*"',
+       ],
+       loggrep => { qr/ (?:done|last write \(done\)), \[X-Header-Client: ABC\]\ \[X-Header-Server: XYZ\]/ => 1 },
+    },
+    server => {
+       func => \&http_server,
+       header => \%header_server,
+       loggrep => {
+           "X-Header-Client: ABC" => 1,
+           "X-Header-Client: abc" => 1,
+       },
+    },
+);
+
+1;
index 4928fcf..9e30487 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: relay_http.c,v 1.26 2014/07/12 14:34:13 reyk Exp $    */
+/*     $OpenBSD: relay_http.c,v 1.27 2014/07/12 15:47:18 benno Exp $   */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -1437,11 +1437,8 @@ relay_apply_actions(struct ctl_relay_event *cre, struct kvlist *actions)
                                        if (kv_set(match, "%s",
                                            kv->kv_value) == -1)
                                                goto fail;
-                               } else {
-                                       if (kv_setkey(match, "%s,%s",
-                                           match->kv_key, kv->kv_key) == -1)
-                                               goto fail;
-                               }
+                               } else
+                                       addkv = 1;
                                break;
                        default:
                                /* query, url not supported */