From: Adam Dickmeiss Date: Wed, 8 May 2013 09:29:58 +0000 (+0200) Subject: HTTP encode. Proper Content-Length YAZ-660 X-Git-Tag: v4.2.57~3 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=4d32d8e976a69219ccbe14572d18e2e6fb75ed27 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. --- 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)