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

HTTP: avoid duplicate Content-length
author Adam Chlipala <adam@chlipala.net>
date Thu, 12 Dec 2013 10:24:38 -0500
parents 8e6e3d9cea22
children 6745eafff617
comparison
equal deleted inserted replaced
1933:8e6e3d9cea22 1934:420d129c4174
1343 int len = strlen(s); 1343 int len = strlen(s);
1344 1344
1345 uw_check_headers(ctx, len + 1); 1345 uw_check_headers(ctx, len + 1);
1346 strcpy(ctx->outHeaders.front, s); 1346 strcpy(ctx->outHeaders.front, s);
1347 ctx->outHeaders.front += len; 1347 ctx->outHeaders.front += len;
1348 }
1349
1350 int uw_has_contentLength(uw_context ctx) {
1351 return strstr(ctx->outHeaders.start, "Content-length: ") != NULL;
1348 } 1352 }
1349 1353
1350 void uw_clear_headers(uw_context ctx) { 1354 void uw_clear_headers(uw_context ctx) {
1351 uw_buffer_reset(&ctx->outHeaders); 1355 uw_buffer_reset(&ctx->outHeaders);
1352 } 1356 }
3721 uw_buffer_reset(&ctx->page); 3725 uw_buffer_reset(&ctx->page);
3722 3726
3723 uw_write_header(ctx, on_success); 3727 uw_write_header(ctx, on_success);
3724 uw_write_header(ctx, "Content-Type: "); 3728 uw_write_header(ctx, "Content-Type: ");
3725 uw_write_header(ctx, mimeType); 3729 uw_write_header(ctx, mimeType);
3726 uw_write_header(ctx, "\r\nContent-Length: "); 3730 uw_write_header(ctx, "\r\nContent-length: ");
3727 ctx_uw_buffer_check(ctx, "headers", &ctx->outHeaders, INTS_MAX); 3731 ctx_uw_buffer_check(ctx, "headers", &ctx->outHeaders, INTS_MAX);
3728 sprintf(ctx->outHeaders.front, "%lu%n", (unsigned long)b.size, &len); 3732 sprintf(ctx->outHeaders.front, "%lu%n", (unsigned long)b.size, &len);
3729 ctx->outHeaders.front += len; 3733 ctx->outHeaders.front += len;
3730 uw_write_header(ctx, "\r\n"); 3734 uw_write_header(ctx, "\r\n");
3731 if (oldh) uw_write_header(ctx, oldh); 3735 if (oldh) uw_write_header(ctx, oldh);
3753 uw_buffer_reset(&ctx->outHeaders); 3757 uw_buffer_reset(&ctx->outHeaders);
3754 3758
3755 uw_write_header(ctx, on_success); 3759 uw_write_header(ctx, on_success);
3756 uw_write_header(ctx, "Content-Type: "); 3760 uw_write_header(ctx, "Content-Type: ");
3757 uw_write_header(ctx, mimeType); 3761 uw_write_header(ctx, mimeType);
3758 uw_write_header(ctx, "\r\nContent-Length: "); 3762 uw_write_header(ctx, "\r\nContent-length: ");
3759 ctx_uw_buffer_check(ctx, "headers", &ctx->outHeaders, INTS_MAX); 3763 ctx_uw_buffer_check(ctx, "headers", &ctx->outHeaders, INTS_MAX);
3760 sprintf(ctx->outHeaders.front, "%lu%n", (unsigned long)uw_buffer_used(&ctx->page), &len); 3764 sprintf(ctx->outHeaders.front, "%lu%n", (unsigned long)uw_buffer_used(&ctx->page), &len);
3761 ctx->outHeaders.front += len; 3765 ctx->outHeaders.front += len;
3762 uw_write_header(ctx, "\r\n"); 3766 uw_write_header(ctx, "\r\n");
3763 if (oldh) uw_write_header(ctx, oldh); 3767 if (oldh) uw_write_header(ctx, oldh);