comparison src/c/urweb.c @ 1409:6ab04cb0e4db

More fixes for FastCGI
author Adam Chlipala <adam@chlipala.net>
date Thu, 20 Jan 2011 16:56:54 -0500
parents 56ba9c442a2d
children 55d0c8b01d18
comparison
equal deleted inserted replaced
1408:56ba9c442a2d 1409:6ab04cb0e4db
239 pthread_mutex_unlock(&clients_mutex); 239 pthread_mutex_unlock(&clients_mutex);
240 return c; 240 return c;
241 } 241 }
242 242
243 static char *on_success = "HTTP/1.1 200 OK\r\n"; 243 static char *on_success = "HTTP/1.1 200 OK\r\n";
244 static char *on_redirect = "HTTP/1.1 303 See Other\r\n";
244 245
245 void uw_set_on_success(char *s) { 246 void uw_set_on_success(char *s) {
246 on_success = s; 247 on_success = s;
247 } 248 }
248 249
3401 ctx_uw_buffer_check(ctx, "page", &ctx->page, uw_buffer_used(&ctx->outHeaders)+1); 3402 ctx_uw_buffer_check(ctx, "page", &ctx->page, uw_buffer_used(&ctx->outHeaders)+1);
3402 memcpy(ctx->page.start, ctx->outHeaders.start, uw_buffer_used(&ctx->outHeaders)); 3403 memcpy(ctx->page.start, ctx->outHeaders.start, uw_buffer_used(&ctx->outHeaders));
3403 ctx->page.start[uw_buffer_used(&ctx->outHeaders)] = 0; 3404 ctx->page.start[uw_buffer_used(&ctx->outHeaders)] = 0;
3404 uw_buffer_reset(&ctx->outHeaders); 3405 uw_buffer_reset(&ctx->outHeaders);
3405 3406
3406 uw_write_header(ctx, on_success); 3407 if (on_success[0])
3407 3408 uw_write_header(ctx, on_redirect);
3408 s = strchr(ctx->page.start, '\n'); 3409 else
3410 uw_write_header(ctx, "Status: 303 See Other\r\n");
3411 s = on_success[0] ? strchr(ctx->page.start, '\n') : ctx->page.start;
3409 if (s) { 3412 if (s) {
3410 char *s2; 3413 char *s2;
3411 for (++s; (s2 = strchr(s, '\n')); s = s2+1) { 3414 if (s[0] == '\n') ++s;
3415 for (; (s2 = strchr(s, '\n')); s = s2+1) {
3412 *s2 = 0; 3416 *s2 = 0;
3413 if (!strncmp(s, "Set-Cookie: ", 12)) { 3417 if (!strncmp(s, "Set-Cookie: ", 12)) {
3414 uw_write_header(ctx, s); 3418 uw_write_header(ctx, s);
3415 uw_write_header(ctx, "\n"); 3419 uw_write_header(ctx, "\n");
3416 } 3420 }
3739 if (ctx->app->on_error) { 3743 if (ctx->app->on_error) {
3740 if (r == 0) { 3744 if (r == 0) {
3741 if (ctx->app->db_begin(ctx)) 3745 if (ctx->app->db_begin(ctx))
3742 uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN"); 3746 uw_error(ctx, BOUNDED_RETRY, "Error running SQL BEGIN");
3743 3747
3744 uw_write_header(ctx, "Status: 500 Internal Server Error\r\n"); 3748 uw_buffer_reset(&ctx->outHeaders);
3749 if (on_success[0])
3750 uw_write_header(ctx, "HTTP/1.1 ");
3751 else
3752 uw_write_header(ctx, "Status: ");
3753 uw_write_header(ctx, "500 Internal Server Error\r\n");
3745 uw_write_header(ctx, "Content-type: text/html\r\n\r\n"); 3754 uw_write_header(ctx, "Content-type: text/html\r\n\r\n");
3746 uw_write(ctx, begin_xhtml); 3755 uw_write(ctx, begin_xhtml);
3747 ctx->app->on_error(ctx, msg); 3756 ctx->app->on_error(ctx, msg);
3748 uw_write(ctx, "</html>"); 3757 uw_write(ctx, "</html>");
3749 } 3758 }