auto-response-header: make value optional
authorSébastien Marie <semarie@users.noreply.github.com>
Sat, 1 Nov 2014 18:10:58 +0000 (19:10 +0100)
committerSébastien Marie <semarie@users.noreply.github.com>
Sat, 1 Nov 2014 18:10:58 +0000 (19:10 +0100)
an optional value result removing a previously setted header.

doc/vimb.1
src/arh.c

index 94cea53..3a0b719 100644 (file)
@@ -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:
index ffb895e..bcbc2ba 100644 (file)
--- 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);
         }
     }
 }