From cdd681d602980f8d6862a168eea5f3b40bd5a033 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Sun, 12 Sep 2021 14:30:33 +0200 Subject: [PATCH] Let http_response_header() handle duplicates. If a response header was previously by an application for an HTTP request http_response_header() will now overwrite the previous value. --- src/http.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/http.c b/src/http.c index 993e8fb..665aa3a 100644 --- a/src/http.c +++ b/src/http.c @@ -400,11 +400,24 @@ http_response_header(struct http_request *req, { struct http_header *hdr; + hdr = NULL; kore_debug("http_response_header(%p, %s, %s)", req, header, value); - hdr = kore_pool_get(&http_header_pool); + TAILQ_FOREACH(hdr, &req->resp_headers, list) { + if (!strcasecmp(hdr->header, header)) { + TAILQ_REMOVE(&req->resp_headers, hdr, list); + kore_free(hdr->header); + kore_free(hdr->value); + break; + } + } + + if (hdr == NULL) + hdr = kore_pool_get(&http_header_pool); + hdr->header = kore_strdup(header); hdr->value = kore_strdup(value); + TAILQ_INSERT_TAIL(&(req->resp_headers), hdr, list); }