]> granicus.if.org Git - libevent/commitdiff
fix cases where there is no content or transfer encoding was specified
authorNiels Provos <provos@gmail.com>
Sat, 2 Dec 2006 21:28:39 +0000 (21:28 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 2 Dec 2006 21:28:39 +0000 (21:28 +0000)
from Dug Song

svn:r291

http.c

diff --git a/http.c b/http.c
index d8e134faeea26e994630093156ea4155d026346c..aec8df37811d2de9eaba1236e22eda80f9726829 100644 (file)
--- a/http.c
+++ b/http.c
@@ -302,21 +302,26 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
            req->response_code_line);
        evbuffer_add(evcon->output_buffer, line, strlen(line));
 
-       /* Potentially add headers */
-       if (evhttp_find_header(req->output_headers, "Content-Type") == NULL) {
+       /* Potentially add headers for unidentified content. */
+       if (EVBUFFER_LENGTH(req->output_buffer) &&
+           evhttp_find_header(req->output_headers, "Content-Type") == NULL) {
                evhttp_add_header(req->output_headers,
                    "Content-Type", "text/html; charset=ISO-8859-1");
-       }
-
-       /* 
-        * we need to add the content length if the user did not give it,
-        * this is required for persistent connections to work.
-        */
-       if (evhttp_find_header(req->output_headers, "Content-Length") == NULL){
-               static char len[12];
-               snprintf(len, sizeof(len), "%ld",
-                        (long)EVBUFFER_LENGTH(req->output_buffer));
-               evhttp_add_header(req->output_headers, "Content-Length", len);
+               /* 
+                * we need to add the content length if the user did
+                * not give it, this is required for persistent
+                * connections to work.
+                */
+               if (evhttp_find_header(req->output_headers,
+                       "Transfer-Encoding") == NULL &&
+                   evhttp_find_header(req->output_headers,
+                       "Content-Length") == NULL) {
+                       static char len[12];
+                       snprintf(len, sizeof(len), "%ld",
+                           (long)EVBUFFER_LENGTH(req->output_buffer));
+                       evhttp_add_header(req->output_headers,
+                           "Content-Length", len);
+               }
        }
 
        /* if the request asked for a close, we send a close, too */