From 858131ba57ca67c50447aa0bd0c0fc66d5fa2cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 25 Mar 2014 19:20:56 +0100 Subject: [PATCH] merge duplicated headers when SPDY is enabled, fixes #572 --- plugins/http/spdy3.c | 50 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/plugins/http/spdy3.c b/plugins/http/spdy3.c index b07f43e9..b55df4e2 100644 --- a/plugins/http/spdy3.c +++ b/plugins/http/spdy3.c @@ -180,8 +180,10 @@ struct uwsgi_buffer *spdy_http_to_spdy(char *buf, size_t len, uint32_t *hh) { if (!key) return ub; uint32_t h_len = 0; - - // headers (key lowercase...) + // merge header values and ensure keys are all lowercase + struct uwsgi_string_list *hr=NULL, *usl=NULL; + char *line_value; + size_t line_key_len, line_value_len; for(i=next;icustom_ptr; + usl->custom_ptr = uwsgi_concat3n(usl->custom_ptr, usl->custom, "\0", 1, line_value, line_value_len); + usl->custom = usl->custom + 1 + line_value_len; + free(oldval); + } + else { + // this key is new + usl = uwsgi_string_new_list(&hr, key); + usl->custom_ptr = line_value; + usl->custom = line_value_len; + } + } + else { + // this is first key + usl = uwsgi_string_new_list(&hr, key); + usl->custom_ptr = line_value; + usl->custom = line_value_len; } - if (uwsgi_buffer_append_keyval32(ub, key, colon-key, colon+2, h_len-((colon-key)+2))) goto end; - *hh+=1; key = NULL; h_len = 0; } @@ -211,6 +239,18 @@ struct uwsgi_buffer *spdy_http_to_spdy(char *buf, size_t len, uint32_t *hh) { } } } + + // append all merged header lines to buffer and free memory + struct uwsgi_string_list *ohr; + while (hr) { + if (uwsgi_buffer_append_keyval32(ub, hr->value, hr->len, hr->custom_ptr, hr->custom)) goto end; + *hh+=1; + ohr = hr; + hr = hr->next; + free(ohr->custom_ptr); + free(ohr); + } + return ub; end: