summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-11-27 15:28:55 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2013-11-27 15:28:55 -0500
commit160ebb4779e0e6990fc7c500681b626b50422db7 (patch)
treecb66e67b322fe577e3096fbb07172f30b06ab0b3
parent4fccf2716d742dfff33d868f04e940075c07d93a (diff)
Add Connection and Content-length headers to raw HTTP responses
-rw-r--r--include/urweb/urweb_cpp.h1
-rw-r--r--src/c/http.c9
-rw-r--r--src/c/urweb.c4
3 files changed, 13 insertions, 1 deletions
diff --git a/include/urweb/urweb_cpp.h b/include/urweb/urweb_cpp.h
index 91342933..4779b95a 100644
--- a/include/urweb/urweb_cpp.h
+++ b/include/urweb/urweb_cpp.h
@@ -58,6 +58,7 @@ void uw_memstats(struct uw_context *);
int uw_send(struct uw_context *, int sock);
int uw_print(struct uw_context *, int fd);
int uw_output(struct uw_context * ctx, int (*output)(void *data, const char *buf, size_t len), void *data);
+int uw_pagelen(struct uw_context *);
int uw_set_input(struct uw_context *, const char *name, char *value);
int uw_set_file_input(struct uw_context *, char *name, uw_Basis_file);
diff --git a/src/c/http.c b/src/c/http.c
index 48a042dc..ba9214c5 100644
--- a/src/c/http.c
+++ b/src/c/http.c
@@ -204,7 +204,14 @@ static void *worker(void *data) {
on_success, on_failure,
NULL, log_error, log_debug,
sock, uw_really_send, close);
- if (rr != KEEP_OPEN) uw_send(ctx, sock);
+ if (rr != KEEP_OPEN) {
+ char clen[100];
+
+ uw_write_header(ctx, "Connection: close\r\n");
+ sprintf(clen, "Content-length: %d\r\n", uw_pagelen(ctx));
+ uw_write_header(ctx, clen);
+ uw_send(ctx, sock);
+ }
if (rr == SERVED || rr == FAILED)
close(sock);
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 447733be..82bbf39f 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -1282,6 +1282,10 @@ void uw_memstats(uw_context ctx) {
printf("Heap: %lu/%lu\n", (unsigned long)uw_buffer_used(&ctx->heap), (unsigned long)uw_buffer_avail(&ctx->heap));
}
+int uw_pagelen(uw_context ctx) {
+ return ctx->page.front - ctx->page.start;
+}
+
int uw_send(uw_context ctx, int sock) {
int n = uw_really_send(sock, ctx->outHeaders.start, ctx->outHeaders.front - ctx->outHeaders.start);