-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test1662: verify formpost, 302 redirect, no rewind possible
Reproduces #9735 and verifies the subsequent fix. The original issue uses a pipe that cannot be rewound, but this test case instead sets a callback without rewind ability to get roughly the same properties but being a much more portable test.
- Loading branch information
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<testcase><testcase> | ||
<info> | ||
<keywords> | ||
HTTP | ||
HTTP POST | ||
</keywords> | ||
</info> | ||
|
||
# | ||
# Server-side | ||
<reply> | ||
<data nocheck="yes"> | ||
HTTP/1.1 301 OK | ||
Date: Tue, 09 Nov 2010 14:49:00 GMT | ||
Server: test-server/fake | ||
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT | ||
ETag: "21025-dc7-39462498" | ||
Accept-Ranges: bytes | ||
Content-Length: 6 | ||
Location: %TESTNUMBER0002 | ||
Content-Type: text/html | ||
Funny-head: yesyes | ||
|
||
-foo- | ||
</data> | ||
<data2 nocheck="yes"> | ||
HTTP/1.1 200 OK | ||
Content-Length: 6 | ||
Connection: close | ||
Funny-head: nono | ||
|
||
-bar- | ||
</data2> | ||
</reply> | ||
|
||
# | ||
# Client-side | ||
<client> | ||
<features> | ||
Mime | ||
debug | ||
</features> | ||
<server> | ||
http | ||
</server> | ||
<name> | ||
HTTP formpost from callback and a redirect and switch to GET | ||
</name> | ||
<tool> | ||
lib%TESTNUMBER | ||
</tool> | ||
<command> | ||
http://%HOSTIP:%HTTPPORT/%TESTNUMBER | ||
</command> | ||
<stdin> | ||
mooaaa | ||
</stdin> | ||
</client> | ||
|
||
# | ||
# Verify data after the test has been "shot" | ||
<verify> | ||
<protocol> | ||
POST /%TESTNUMBER HTTP/1.1 | ||
Host: %HOSTIP:%HTTPPORT | ||
User-Agent: curl/2000 | ||
Accept: */* | ||
Transfer-Encoding: chunked | ||
Content-Type: multipart/form-data; boundary=------------------------3433323135333231 | ||
Expect: 100-continue | ||
|
||
95 | ||
--------------------------3433323135333231 | ||
Content-Disposition: form-data; name="content"; filename="poetry.txt" | ||
Content-Type: text/plain | ||
|
||
mooaaa | ||
30 | ||
|
||
--------------------------3433323135333231-- | ||
|
||
0 | ||
|
||
GET /%TESTNUMBER0002 HTTP/1.1 | ||
Host: %HOSTIP:%HTTPPORT | ||
User-Agent: curl/2000 | ||
Accept: */* | ||
|
||
</protocol> | ||
</verify> | ||
</testcase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*************************************************************************** | ||
* _ _ ____ _ | ||
* Project ___| | | | _ \| | | ||
* / __| | | | |_) | | | ||
* | (__| |_| | _ <| |___ | ||
* \___|\___/|_| \_\_____| | ||
* | ||
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al. | ||
* | ||
* This software is licensed as described in the file COPYING, which | ||
* you should have received as part of this distribution. The terms | ||
* are also available at https://curl.se/docs/copyright.html. | ||
* | ||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell | ||
* copies of the Software, and permit persons to whom the Software is | ||
* furnished to do so, under the terms of the COPYING file. | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
* KIND, either express or implied. | ||
* | ||
* SPDX-License-Identifier: curl | ||
* | ||
***************************************************************************/ | ||
#include "test.h" | ||
|
||
static char data[]="mooaaa"; | ||
|
||
struct WriteThis { | ||
size_t sizeleft; | ||
}; | ||
|
||
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) | ||
{ | ||
struct WriteThis *pooh = (struct WriteThis *)userp; | ||
size_t len = strlen(data); | ||
|
||
if(size*nmemb < len) | ||
return 0; | ||
|
||
if(pooh->sizeleft) { | ||
memcpy(ptr, data, strlen(data)); | ||
pooh->sizeleft = 0; | ||
return len; | ||
} | ||
|
||
return 0; /* no more data left to deliver */ | ||
} | ||
|
||
|
||
int test(char *URL) | ||
{ | ||
CURLcode res = CURLE_OK; | ||
CURL *hnd; | ||
curl_mime *mime1; | ||
curl_mimepart *part1; | ||
struct WriteThis pooh = { 1 }; | ||
|
||
mime1 = NULL; | ||
|
||
global_init(CURL_GLOBAL_ALL); | ||
|
||
hnd = curl_easy_init(); | ||
if(hnd) { | ||
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L); | ||
curl_easy_setopt(hnd, CURLOPT_URL, URL); | ||
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); | ||
mime1 = curl_mime_init(hnd); | ||
if(mime1) { | ||
part1 = curl_mime_addpart(mime1); | ||
curl_mime_data_cb(part1, -1, read_callback, NULL, NULL, &pooh); | ||
curl_mime_filename(part1, "poetry.txt"); | ||
curl_mime_name(part1, "content"); | ||
curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1); | ||
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/2000"); | ||
curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L); | ||
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); | ||
curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, | ||
(long)CURL_HTTP_VERSION_2TLS); | ||
curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); | ||
curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); | ||
curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); | ||
res = curl_easy_perform(hnd); | ||
} | ||
} | ||
|
||
curl_easy_cleanup(hnd); | ||
curl_mime_free(mime1); | ||
curl_global_cleanup(); | ||
return (int)res; | ||
} | ||
|