Mercurial > urweb
comparison src/c/urweb.c @ 1932:98895243b5b6
Change handling of returned text blobs, to activate the normal EWrite optimizations
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Wed, 11 Dec 2013 18:22:10 -0500 |
parents | 1a04b1edded2 |
children | 8e6e3d9cea22 |
comparison
equal
deleted
inserted
replaced
1931:1a04b1edded2 | 1932:98895243b5b6 |
---|---|
1347 ctx->outHeaders.front += len; | 1347 ctx->outHeaders.front += len; |
1348 } | 1348 } |
1349 | 1349 |
1350 void uw_clear_headers(uw_context ctx) { | 1350 void uw_clear_headers(uw_context ctx) { |
1351 uw_buffer_reset(&ctx->outHeaders); | 1351 uw_buffer_reset(&ctx->outHeaders); |
1352 } | |
1353 | |
1354 void uw_Basis_clear_page(uw_context ctx) { | |
1355 uw_buffer_reset(&ctx->page); | |
1352 } | 1356 } |
1353 | 1357 |
1354 static void uw_check_script(uw_context ctx, size_t extra) { | 1358 static void uw_check_script(uw_context ctx, size_t extra) { |
1355 ctx_uw_buffer_check(ctx, "script", &ctx->script, extra); | 1359 ctx_uw_buffer_check(ctx, "script", &ctx->script, extra); |
1356 } | 1360 } |
3734 ctx->cleanup_front = ctx->cleanup; | 3738 ctx->cleanup_front = ctx->cleanup; |
3735 | 3739 |
3736 longjmp(ctx->jmp_buf, RETURN_INDIRECTLY); | 3740 longjmp(ctx->jmp_buf, RETURN_INDIRECTLY); |
3737 } | 3741 } |
3738 | 3742 |
3743 __attribute__((noreturn)) void uw_return_blob_from_page(uw_context ctx, uw_Basis_string mimeType) { | |
3744 cleanup *cl; | |
3745 int len; | |
3746 char *oldh; | |
3747 | |
3748 if (!ctx->allowed_to_return_indirectly) | |
3749 uw_error(ctx, FATAL, "Tried to return a blob from an RPC"); | |
3750 | |
3751 ctx->returning_indirectly = 1; | |
3752 oldh = old_headers(ctx); | |
3753 uw_buffer_reset(&ctx->outHeaders); | |
3754 | |
3755 uw_write_header(ctx, on_success); | |
3756 uw_write_header(ctx, "Content-Type: "); | |
3757 uw_write_header(ctx, mimeType); | |
3758 uw_write_header(ctx, "\r\nContent-Length: "); | |
3759 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); | |
3761 ctx->outHeaders.front += len; | |
3762 uw_write_header(ctx, "\r\n"); | |
3763 if (oldh) uw_write_header(ctx, oldh); | |
3764 | |
3765 for (cl = ctx->cleanup; cl < ctx->cleanup_front; ++cl) | |
3766 cl->func(cl->arg); | |
3767 | |
3768 ctx->cleanup_front = ctx->cleanup; | |
3769 | |
3770 longjmp(ctx->jmp_buf, RETURN_INDIRECTLY); | |
3771 } | |
3772 | |
3739 __attribute__((noreturn)) void uw_redirect(uw_context ctx, uw_Basis_string url) { | 3773 __attribute__((noreturn)) void uw_redirect(uw_context ctx, uw_Basis_string url) { |
3740 cleanup *cl; | 3774 cleanup *cl; |
3741 char *s; | 3775 char *s; |
3742 char *oldh; | 3776 char *oldh; |
3743 | 3777 |