From fb9493a090a01b5dfa393b3eb4d800b01e178d33 Mon Sep 17 00:00:00 2001 From: "Arnout Vandecappelle (Essensium/Mind)" Date: Mon, 29 Nov 2010 16:27:30 +0100 Subject: [PATCH] Bugfix of Issue #180: mg_read() should accept PUT requests. --- mongoose.c | 3 +-- test/embed.c | 4 +++- test/test.pl | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mongoose.c b/mongoose.c index d4bc3900..950c0a8c 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1322,8 +1322,7 @@ int mg_read(struct mg_connection *conn, void *buf, size_t len) { DEBUG_TRACE(("%p %zu %lld %lld", buf, len, conn->content_len, conn->consumed_content)); nread = 0; - if (strcmp(conn->request_info.request_method, "POST") == 0 && - conn->consumed_content < conn->content_len) { + if (conn->consumed_content < conn->content_len) { // Adjust number of bytes to read. int64_t to_read = conn->content_len - conn->consumed_content; diff --git a/test/embed.c b/test/embed.c index 74c4b999..90f88560 100644 --- a/test/embed.c +++ b/test/embed.c @@ -51,7 +51,9 @@ static void test_get_var(struct mg_connection *conn, var = buf = NULL; cl = mg_get_header(conn, "Content-Length"); mg_printf(conn, "cl: %p\n", cl); - if (!strcmp(ri->request_method, "POST") && cl != NULL) { + printf("reqeust method = %s\n", ri->request_method); + if ((!strcmp(ri->request_method, "POST") || !strcmp(ri->request_method, "PUT")) + && cl != NULL) { buf_len = atoi(cl); buf = malloc(buf_len); mg_read(conn, buf, buf_len); diff --git a/test/test.pl b/test/test.pl index 1edf4cda..8c46fead 100644 --- a/test/test.pl +++ b/test/test.pl @@ -425,6 +425,10 @@ sub do_embedded_test { o("POST /test_get_var HTTP/1.0\nContent-Length: 64007\n\n". "my_var=$my_var", 'Value size: \[64000\]', 'mg_get_var 10', 0); + # Other methods should also work + o("PUT /test_get_var HTTP/1.0\nContent-Length: 10\n\n". + "my_var=foo", 'Value: \[foo\]', 'mg_get_var 11', 0); + o("POST /test_get_request_info?xx=yy HTTP/1.0\nFoo: bar\n". "Content-Length: 3\n\na=b", 'Method: \[POST\].URI: \[/test_get_request_info\].'.