From: Sébastien Marie <semarie@users.noreply.github.com>
Date: Sat, 1 Nov 2014 18:10:58 +0000 (+0100)
Subject: auto-response-header: make value optional
X-Git-Url: https://git.owens.tech/editable-focus.html/editable-focus.html/git?a=commitdiff_plain;h=01cb4a6f4e311b644cb1a1852c02e8df4376e12b;p=vimb.git

auto-response-header: make value optional

an optional value result removing a previously setted header.
---

diff --git a/doc/vimb.1 b/doc/vimb.1
index 94cea53..3a0b719 100644
--- a/doc/vimb.1
+++ b/doc/vimb.1
@@ -1209,7 +1209,8 @@ If multiple patterns match a request uri, the last matched rule will be
 applied. You could also specified differents headers for same pattern.
 
 The format is: `pattern name=value`. For each request matching `pattern`, an
-HTTP header "name: value" will be added to the response.
+HTTP header "name: value" will be added to the response. If value is empty, a
+previously added header could be removed.
 .RS
 .PP
 Example:
diff --git a/src/arh.c b/src/arh.c
index ffb895e..bcbc2ba 100644
--- a/src/arh.c
+++ b/src/arh.c
@@ -50,7 +50,7 @@ GSList *arh_parse(const char *data, const char **error)
         char *name    = read_name(&parse);
         char *value   = read_value(&parse);
 
-        if (pattern && name && value) {
+        if (pattern && name) {
             MatchARH *marh = g_slice_new0(MatchARH);
 
             marh->pattern = g_strdup(pattern);
@@ -103,12 +103,20 @@ void arh_run(GSList *list, const char *uri, SoupMessage *msg)
         MatchARH *marh = (MatchARH *)l->data;
 
         if (util_wildmatch(marh->pattern, uri)) {
-            /* the pattern match, so replace headers 
-	     * as side-effect, for one header the last matched will be keeped */
-            soup_message_headers_replace(msg->response_headers,
-                    marh->name, marh->value);
+            if (marh->value) {
+                /* the pattern match, so replace headers
+                 * as side-effect, for one header the last matched will be keeped */
+                soup_message_headers_replace(msg->response_headers,
+                        marh->name, marh->value);
+
+                PRINT_DEBUG(" header added: %s: %s", marh->name, marh->value);
+            } else {
+                /* remove a previously setted auto-reponse-header */
+                soup_message_headers_remove(msg->response_headers, marh->name);
+
+                PRINT_DEBUG(" header removed: %s", marh->name);
+            }
 
-            PRINT_DEBUG(" header added: %s: %s", marh->name, marh->value);
         }
     }
 }