From c67a99ff27036c824be15f01e21b91c3ec08da4a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 29 Aug 2008 10:47:59 +0000 Subject: - When libcurl was doing a HTTP POST and the server would respond with "Connection: close" and actually close the connection after the response-body, libcurl could still have outstanding data to send and it would not properly notice this and stop sending. This caused weirdness and sad faces. http://curl.haxx.se/bug/view.cgi?id=2080222 Note that there are still reasons to consider libcurl's behavior when getting a >= 400 response code while sending data, as Craig Perras' note "http upload: how to stop on error" specifies: http://curl.haxx.se/mail/archive-2008-08/0138.html --- tests/FILEFORMAT | 10 +++++---- tests/data/test1070 | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/server/sws.c | 36 +++++++++++++++++++++++------ 3 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 tests/data/test1070 (limited to 'tests') diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT index 555cee52d..e4be47ab4 100644 --- a/tests/FILEFORMAT +++ b/tests/FILEFORMAT @@ -113,12 +113,14 @@ PASVBADIP - makes PASV send back an illegal IP in its 227 response For HTTP/HTTPS: -auth_required - if this is set and a POST/PUT is made without auth, the +auth_required if this is set and a POST/PUT is made without auth, the server will NOT wait for the full request body to get sent -idle - do nothing after receiving the request, just "sit idle" -stream - continuously send data to the client, never-ending -pipe: [num] - tell the server to expect this many HTTP requests before +idle do nothing after receiving the request, just "sit idle" +stream continuously send data to the client, never-ending +pipe: [num] tell the server to expect this many HTTP requests before sending back anything, to allow pipelining tests +skip: [num] instructs the server to ignore reading this many bytes from a PUT + or POST request diff --git a/tests/data/test1070 b/tests/data/test1070 new file mode 100644 index 000000000..715e4a08d --- /dev/null +++ b/tests/data/test1070 @@ -0,0 +1,65 @@ + + + +HTTP +HTTP POST + + +# +# Server-side + + +HTTP/1.1 403 Go away and swsclose +Server: test-server/fake +Content-Type: text/html +Content-Length: 55 +Connection: close + +you are not supposed to be allowed to send things here + + +skip: 2300 + + + +# +# Client-side + + +http + + +HTTP POST with server sending error before (all) data is received + + + -d @log/input1070 http://%HOSTIP:%HTTPPORT/1070 + + +This creates the named file with this content before the test case is run, +which is useful if the test case needs a file to act on. We create this file +rather large (larger than your typical TCP packet) so that not all of it can nor +will be sent in one go as that is kind of the point of this test! + +Here's 2000 x 'O': +OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO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OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO + + + +# +# Verify data after the test has been "shot" + + +^User-Agent:.* + + +POST /1070 HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +Accept: */* +Content-Length: 2313 +Content-Type: application/x-www-form-urlencoded +Expect: 100-continue + +This creates + + + diff --git a/tests/server/sws.c b/tests/server/sws.c index a114cac43..f658d1863 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -99,6 +99,10 @@ struct httprequest { bool ntlm; /* Authorization ntlm header found */ int pipe; /* if non-zero, expect this many requests to do a "piped" request/response */ + int skip; /* if non-zero, the server is instructed to not read this + many bytes from a PUT/POST request. Ie the client sends N + bytes said in Content-Length, but the server only reads N + - skip bytes. */ int rcmd; /* doing a special command, see defines above */ int prot_version; /* HTTP version * 10 */ bool pipelining; /* true if request is pipelined */ @@ -303,6 +307,13 @@ int ProcessRequest(struct httprequest *req) req->pipe = num-1; /* decrease by one since we don't count the first request in this number */ } + else if(1 == sscanf(cmd, "skip: %d", &num)) { + logmsg("instructed to skip this number of bytes %d", num); + req->skip = num; + } + else { + logmsg("funny instruction found: %s", cmd); + } free(cmd); } } @@ -351,7 +362,7 @@ int ProcessRequest(struct httprequest *req) headers, for the pipelining case mostly */ req->checkindex += (end - line) + strlen(END_OF_HEADERS); - /* **** Persistency **** + /* **** Persistence **** * * If the request is a HTTP/1.0 one, we close the connection unconditionally * when we're done. @@ -363,14 +374,17 @@ int ProcessRequest(struct httprequest *req) */ do { - if(!req->cl && curlx_strnequal("Content-Length:", line, 15)) { + if((req->cl<=0) && curlx_strnequal("Content-Length:", line, 15)) { /* If we don't ignore content-length, we read it and we read the whole request including the body before we return. If we've been told to ignore the content-length, we will return as soon as all headers have been received */ - req->cl = strtol(line+15, &line, 10); + size_t cl = strtol(line+15, &line, 10); + req->cl = cl - req->skip; - logmsg("Found Content-Length: %d in the request", req->cl); + logmsg("Found Content-Length: %d in the request", cl); + if(req->skip) + logmsg("... but will abort after %d bytes", req->cl); break; } else if(curlx_strnequal("Transfer-Encoding: chunked", line, @@ -457,7 +471,7 @@ int ProcessRequest(struct httprequest *req) if(req->auth_req && !req->auth) return 1; - if(req->cl) { + if(req->cl > 0) { if(req->cl <= req->offset - (end - req->reqbuf) - strlen(END_OF_HEADERS)) return 1; /* done */ else @@ -552,6 +566,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req) req->digest = FALSE; req->ntlm = FALSE; req->pipe = 0; + req->skip = 0; req->rcmd = RCMD_NORMALREQ; req->prot_version = 0; req->pipelining = FALSE; @@ -564,8 +579,15 @@ static int get_request(curl_socket_t sock, struct httprequest *req) got = pipereq_length; pipereq_length = 0; } - else - got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset); + else { + if(req->skip) + /* we are instructed to not read the entire thing, so we make sure to only + read what we're supposed to and NOT read the enire thing the client + wants to send! */ + got = sread(sock, reqbuf + req->offset, req->cl); + else + got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset); + } if (got <= 0) { if (got < 0) { logmsg("recv() returned error: %d", SOCKERRNO); -- cgit v1.2.3