From 01cb4a6f4e311b644cb1a1852c02e8df4376e12b Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Marie?= Date: Sat, 1 Nov 2014 19:10:58 +0100 Subject: [PATCH] auto-response-header: make value optional an optional value result removing a previously setted header. --- doc/vimb.1 | 3 ++- src/arh.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) 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); } } } -- 2.20.1