diff options
author | Adam Chlipala <adam@chlipala.net> | 2010-12-18 10:56:31 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2010-12-18 10:56:31 -0500 |
commit | 496433cdd2f108b483e4762776dfe1305c466eee (patch) | |
tree | 294baafc0fd3480fdce266c71f27090164d2114c /src/c | |
parent | 8f2b2ce3da639c8a140d21a22b0ae67dbbdc649d (diff) |
postBody type
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/request.c | 5 | ||||
-rw-r--r-- | src/c/urweb.c | 34 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/c/request.c b/src/c/request.c index bcfec5e9..e51f95ae 100644 --- a/src/c/request.c +++ b/src/c/request.c @@ -192,6 +192,9 @@ request_result uw_request(uw_request_context rc, uw_context ctx, boundary[0] = '-'; boundary[1] = '-'; boundary_len = strlen(boundary); + } else if (clen_s && strcasecmp(clen_s, "application/x-www-form-urlencoded")) { + uw_Basis_postBody pb = {clen_s, body}; + uw_postBody(ctx, pb); } } else if (strcmp(method, "GET")) { log_error(logger_data, "Not ready for non-GET/POST command: %s\n", method); @@ -325,7 +328,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx, } } } - else { + else if (!uw_hasPostBody(ctx)) { inputs = is_post ? body : query_string; if (inputs) { diff --git a/src/c/urweb.c b/src/c/urweb.c index 47c6dadf..2b54e87c 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -445,6 +445,9 @@ struct uw_context { void *logger_data; uw_logger log_debug; + int hasPostBody; + uw_Basis_postBody postBody; + char error_message[ERROR_BUF_LEN]; }; @@ -507,6 +510,8 @@ uw_context uw_init(void *logger_data, uw_logger log_debug) { ctx->logger_data = logger_data; ctx->log_debug = log_debug; + ctx->hasPostBody = 0; + return ctx; } @@ -583,6 +588,7 @@ void uw_reset_keep_error_message(uw_context ctx) { ctx->cur_container = NULL; ctx->used_transactionals = 0; ctx->script_header = ""; + ctx->hasPostBody = 0; } void uw_reset_keep_request(uw_context ctx) { @@ -3200,6 +3206,14 @@ uw_Basis_blob uw_Basis_fileData(uw_context ctx, uw_Basis_file f) { return f.data; } +uw_Basis_string uw_Basis_postType(uw_context ctx, uw_Basis_postBody pb) { + return pb.type; +} + +uw_Basis_string uw_Basis_postData(uw_context ctx, uw_Basis_postBody pb) { + return pb.data; +} + __attribute__((noreturn)) void uw_return_blob(uw_context ctx, uw_Basis_blob b, uw_Basis_string mimeType) { cleanup *cl; int len; @@ -3458,3 +3472,23 @@ uw_Basis_int uw_Basis_rand(uw_context ctx) { uw_Basis_int n = abs(rand()); return n; } + +void uw_noPostBody(uw_context ctx) { + ctx->hasPostBody = 0; +} + +void uw_postBody(uw_context ctx, uw_Basis_postBody pb) { + ctx->hasPostBody = 1; + ctx->postBody = pb; +} + +int uw_hasPostBody(uw_context ctx) { + return ctx->hasPostBody; +} + +uw_Basis_postBody uw_getPostBody(uw_context ctx) { + if (ctx->hasPostBody) + return ctx->postBody; + else + uw_error(ctx, FATAL, "Asked for POST body when none exists"); +} |