comparison src/c/http.c @ 1915:52e88e139b25

Add Connection and Content-length headers to raw HTTP responses
author Adam Chlipala <adam@chlipala.net>
date Wed, 27 Nov 2013 15:28:55 -0500
parents 6a2cc604a322
children 398298ca82b9
comparison
equal deleted inserted replaced
1914:6a2cc604a322 1915:52e88e139b25
202 printf("Serving URI %s....\n", path); 202 printf("Serving URI %s....\n", path);
203 rr = uw_request(rc, ctx, method, path, query_string, body, back - body, 203 rr = uw_request(rc, ctx, method, path, query_string, body, back - body,
204 on_success, on_failure, 204 on_success, on_failure,
205 NULL, log_error, log_debug, 205 NULL, log_error, log_debug,
206 sock, uw_really_send, close); 206 sock, uw_really_send, close);
207 if (rr != KEEP_OPEN) uw_send(ctx, sock); 207 if (rr != KEEP_OPEN) {
208 char clen[100];
209
210 uw_write_header(ctx, "Connection: close\r\n");
211 sprintf(clen, "Content-length: %d\r\n", uw_pagelen(ctx));
212 uw_write_header(ctx, clen);
213 uw_send(ctx, sock);
214 }
208 215
209 if (rr == SERVED || rr == FAILED) 216 if (rr == SERVED || rr == FAILED)
210 close(sock); 217 close(sock);
211 else if (rr != KEEP_OPEN) 218 else if (rr != KEEP_OPEN)
212 fprintf(stderr, "Illegal uw_request return code: %d\n", rr); 219 fprintf(stderr, "Illegal uw_request return code: %d\n", rr);