From 4d32d8e976a69219ccbe14572d18e2e6fb75ed27 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 8 May 2013 11:29:58 +0200 Subject: [PATCH] HTTP encode. Proper Content-Length YAZ-660 For yaz_encode_http_response use content_len to determine resulting Content-Length in HTTP response and NOT Content-Length supplied in headers by user. --- src/http.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/http.c b/src/http.c index 6f53119..d16db35 100644 --- a/src/http.c +++ b/src/http.c @@ -573,21 +573,18 @@ int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr) hr->code, z_HTTP_errmsg(hr->code)); odr_write2(o, sbuf, strlen(sbuf)); - /* apply Content-Length if not already applied */ - if (!z_HTTP_header_lookup(hr->headers, - "Content-Length")) - { - char lstr[60]; - sprintf(lstr, "Content-Length: %d\r\n", - hr->content_len); - odr_write2(o, lstr, strlen(lstr)); - } + /* use content_len for Content-Length */ + sprintf(sbuf, "Content-Length: %d\r\n", hr->content_len); + odr_write2(o, sbuf, strlen(sbuf)); for (h = hr->headers; h; h = h->next) { - odr_write2(o, h->name, strlen(h->name)); - odr_write2(o, ": ", 2); - odr_write2(o, h->value, strlen(h->value)); - odr_write2(o, "\r\n", 2); + if (yaz_matchstr(h->name, "Content-Length")) + { /* skip Content-Length if given. content_len rules */ + odr_write2(o, h->name, strlen(h->name)); + odr_write2(o, ": ", 2); + odr_write2(o, h->value, strlen(h->value)); + odr_write2(o, "\r\n", 2); + } } odr_write(o, (unsigned char *) "\r\n", 2); if (hr->content_buf) -- 1.7.10.4