comparison src/c/http.c @ 1934:420d129c4174

HTTP: avoid duplicate Content-length
author Adam Chlipala <adam@chlipala.net>
date Thu, 12 Dec 2013 10:24:38 -0500
parents 1a04b1edded2
children 6745eafff617
comparison
equal deleted inserted replaced
1933:8e6e3d9cea22 1934:420d129c4174
231 on_success, on_failure, 231 on_success, on_failure,
232 NULL, log_error, log_debug, 232 NULL, log_error, log_debug,
233 sock, uw_really_send, close); 233 sock, uw_really_send, close);
234 234
235 if (rr != KEEP_OPEN) { 235 if (rr != KEEP_OPEN) {
236 char clen[100];
237
238 if (keepalive) { 236 if (keepalive) {
239 char *connection = uw_Basis_requestHeader(ctx, "Connection"); 237 char *connection = uw_Basis_requestHeader(ctx, "Connection");
240 238
241 should_keepalive = !(connection && !strcmp(connection, "close")); 239 should_keepalive = !(connection && !strcmp(connection, "close"));
242 } 240 }
243 241
244 if (!should_keepalive) 242 if (!should_keepalive)
245 uw_write_header(ctx, "Connection: close\r\n"); 243 uw_write_header(ctx, "Connection: close\r\n");
246 244
247 sprintf(clen, "Content-length: %d\r\n", uw_pagelen(ctx)); 245 if (!uw_has_contentLength(ctx)) {
248 uw_write_header(ctx, clen); 246 char clen[100];
247
248 sprintf(clen, "Content-length: %d\r\n", uw_pagelen(ctx));
249 uw_write_header(ctx, clen);
250 }
251
249 uw_send(ctx, sock); 252 uw_send(ctx, sock);
250 } 253 }
251 254
252 if (rr == SERVED || rr == FAILED) { 255 if (rr == SERVED || rr == FAILED) {
253 if (should_keepalive) { 256 if (should_keepalive) {