# HG changeset patch # User Adam Chlipala # Date 1295560614 18000 # Node ID 6ab04cb0e4db117721cab1cf0da289e9fab2c985 # Parent 56ba9c442a2d73831ad8b521382a3c318f8bdf56 More fixes for FastCGI diff -r 56ba9c442a2d -r 6ab04cb0e4db src/c/urweb.c --- a/src/c/urweb.c Thu Jan 20 16:26:54 2011 -0500 +++ b/src/c/urweb.c Thu Jan 20 16:56:54 2011 -0500 @@ -241,6 +241,7 @@ } static char *on_success = "HTTP/1.1 200 OK\r\n"; +static char *on_redirect = "HTTP/1.1 303 See Other\r\n"; void uw_set_on_success(char *s) { on_success = s; @@ -3403,12 +3404,15 @@ ctx->page.start[uw_buffer_used(&ctx->outHeaders)] = 0; uw_buffer_reset(&ctx->outHeaders); - uw_write_header(ctx, on_success); - - s = strchr(ctx->page.start, '\n'); + if (on_success[0]) + uw_write_header(ctx, on_redirect); + else + uw_write_header(ctx, "Status: 303 See Other\r\n"); + s = on_success[0] ? strchr(ctx->page.start, '\n') : ctx->page.start; if (s) { char *s2; - for (++s; (s2 = strchr(s, '\n')); s = s2+1) { + if (s[0] == '\n') ++s; + for (; (s2 = strchr(s, '\n')); s = s2+1) { *s2 = 0; if (!strncmp(s, "Set-Cookie: ", 12)) { uw_write_header(ctx, s); @@ -3741,7 +3745,12 @@ if (ctx->app->db_begin(ctx)) uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN"); - uw_write_header(ctx, "Status: 500 Internal Server Error\r\n"); + uw_buffer_reset(&ctx->outHeaders); + if (on_success[0]) + uw_write_header(ctx, "HTTP/1.1 "); + else + uw_write_header(ctx, "Status: "); + uw_write_header(ctx, "500 Internal Server Error\r\n"); uw_write_header(ctx, "Content-type: text/html\r\n\r\n"); uw_write(ctx, begin_xhtml); ctx->app->on_error(ctx, msg);