r7014: added Content-Length header to both esp and non-esp output
authorAndrew Tridgell <tridge@samba.org>
Fri, 27 May 2005 12:05:36 +0000 (12:05 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:06 +0000 (13:17 -0500)
(This used to be commit e0673dcfc0056b3a1b72ef0b10d82948ca8c9819)

source4/web_server/http.c

index 11ddec552d2f6ae25d98f612124d0a9303a7d656..36704a1370493e607b6e921491ab5efaf294dfcc 100644 (file)
@@ -60,6 +60,7 @@ static void http_output_headers(struct websrv_context *web)
        int i;
        char *s;
        DATA_BLOB b;
+       uint32_t content_length = 0;
        const char *response_string = "Unknown Code";
        const struct {
                unsigned code;
@@ -90,7 +91,15 @@ static void http_output_headers(struct websrv_context *web)
        for (i=0;web->output.headers[i];i++) {
                s = talloc_asprintf_append(s, "%s\r\n", web->output.headers[i]);
        }
-       s = talloc_asprintf_append(s, "\r\n");
+
+       /* work out the content length */
+       content_length = web->output.content.length;
+       if (web->output.fd != -1) {
+               struct stat st;
+               fstat(web->output.fd, &st);
+               content_length += st.st_size;
+       }
+       s = talloc_asprintf_append(s, "Content-Length: %u\r\n\r\n", content_length);
        if (s == NULL) return;
 
        b = web->output.content;