mirror of
https://github.com/curl/curl.git
synced 2024-12-27 06:59:43 +08:00
tests: add test1598 for POST with trailers
- test POST fields with trailers and chunked encoding Ref: #12938 Closes #13009
This commit is contained in:
parent
32e0544dc8
commit
5083809529
@ -201,7 +201,7 @@ test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \
|
||||
test1566 test1567 test1568 test1569 test1570 \
|
||||
\
|
||||
test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 \
|
||||
\
|
||||
test1598 \
|
||||
test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \
|
||||
test1608 test1609 test1610 test1611 test1612 test1613 test1614 test1615 \
|
||||
\
|
||||
|
59
tests/data/test1598
Normal file
59
tests/data/test1598
Normal file
@ -0,0 +1,59 @@
|
||||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
HTTP
|
||||
HTTP POST
|
||||
CURLOPT_HTTPTRAILER_FUNCTION
|
||||
CURLOPT_HTTPTRAILER_DATA
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
# Server-side
|
||||
<reply>
|
||||
<data nocheck="yes">
|
||||
HTTP/1.0 200 OK swsclose
|
||||
Date: Tue, 09 Nov 2010 14:49:00 GMT
|
||||
Server: test-server/fake
|
||||
</data>
|
||||
</reply>
|
||||
# Client-side
|
||||
<client>
|
||||
<features>
|
||||
http
|
||||
</features>
|
||||
<server>
|
||||
http
|
||||
</server>
|
||||
<name>
|
||||
HTTP POST with trailers at the end
|
||||
</name>
|
||||
<tool>
|
||||
lib%TESTNUMBER
|
||||
</tool>
|
||||
<command>
|
||||
http://%HOSTIP:%HTTPPORT/bzz/%TESTNUMBER
|
||||
</command>
|
||||
<stdin>
|
||||
more than one byte
|
||||
</stdin>
|
||||
</client>
|
||||
|
||||
# Verify data after the test has been "shot"
|
||||
<verify>
|
||||
<protocol>
|
||||
POST /bzz/%TESTNUMBER HTTP/1.1
|
||||
Host: %HOSTIP:%HTTPPORT
|
||||
Accept: */*
|
||||
Trailer: my-super-awesome-trailer, my-other-awesome-trailer
|
||||
Transfer-Encoding: chunked
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
|
||||
11
|
||||
xxx=yyy&aaa=bbbbb
|
||||
0
|
||||
my-super-awesome-trailer: trail1
|
||||
my-other-awesome-trailer: trail2
|
||||
|
||||
</protocol>
|
||||
</verify>
|
||||
</testcase>
|
@ -62,7 +62,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect libprereq \
|
||||
lib1540 lib1542 lib1543 lib1545 \
|
||||
lib1550 lib1551 lib1552 lib1553 lib1554 lib1555 lib1556 lib1557 \
|
||||
lib1558 lib1559 lib1560 lib1564 lib1565 lib1567 lib1568 lib1569 \
|
||||
lib1591 lib1592 lib1593 lib1594 lib1596 lib1597 \
|
||||
lib1591 lib1592 lib1593 lib1594 lib1596 lib1597 lib1598 \
|
||||
\
|
||||
lib1662 \
|
||||
\
|
||||
@ -534,6 +534,9 @@ lib1596_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1596
|
||||
lib1597_SOURCES = lib1597.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
|
||||
lib1597_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib1598_SOURCES = lib1598.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
|
||||
lib1598_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib1662_SOURCES = lib1662.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
|
||||
lib1662_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
|
107
tests/libtest/lib1598.c
Normal file
107
tests/libtest/lib1598.c
Normal file
@ -0,0 +1,107 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 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
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* This unit test PUT http data over proxy. Proxy header will be different
|
||||
* from server http header
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include <stdio.h>
|
||||
#include "memdebug.h"
|
||||
|
||||
/*
|
||||
* carefully not leak memory on OOM
|
||||
*/
|
||||
static int trailers_callback(struct curl_slist **list, void *userdata)
|
||||
{
|
||||
struct curl_slist *nlist = NULL;
|
||||
struct curl_slist *nlist2 = NULL;
|
||||
(void)userdata;
|
||||
nlist = curl_slist_append(*list, "my-super-awesome-trailer: trail1");
|
||||
if(nlist)
|
||||
nlist2 = curl_slist_append(nlist, "my-other-awesome-trailer: trail2");
|
||||
if(nlist2) {
|
||||
*list = nlist2;
|
||||
return CURL_TRAILERFUNC_OK;
|
||||
}
|
||||
else {
|
||||
curl_slist_free_all(nlist);
|
||||
return CURL_TRAILERFUNC_ABORT;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *post_data = "xxx=yyy&aaa=bbbbb";
|
||||
|
||||
int test(char *URL)
|
||||
{
|
||||
CURL *curl = NULL;
|
||||
CURLcode res = CURLE_FAILED_INIT;
|
||||
/* http and proxy header list */
|
||||
struct curl_slist *hhl = NULL, *list;
|
||||
|
||||
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
||||
fprintf(stderr, "curl_global_init() failed\n");
|
||||
return TEST_ERR_MAJOR_BAD;
|
||||
}
|
||||
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(!curl) {
|
||||
fprintf(stderr, "curl_easy_init() failed\n");
|
||||
curl_global_cleanup();
|
||||
return TEST_ERR_MAJOR_BAD;
|
||||
}
|
||||
|
||||
hhl = curl_slist_append(hhl, "Trailer: my-super-awesome-trailer,"
|
||||
" my-other-awesome-trailer");
|
||||
if(!hhl)
|
||||
goto test_cleanup;
|
||||
if(hhl) {
|
||||
list = curl_slist_append(hhl, "Transfer-Encoding: chunked");
|
||||
if(!list)
|
||||
goto test_cleanup;
|
||||
hhl = list;
|
||||
}
|
||||
|
||||
test_setopt(curl, CURLOPT_URL, URL);
|
||||
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
|
||||
test_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(post_data));
|
||||
test_setopt(curl, CURLOPT_POSTFIELDS, post_data);
|
||||
test_setopt(curl, CURLOPT_TRAILERFUNCTION, trailers_callback);
|
||||
test_setopt(curl, CURLOPT_TRAILERDATA, NULL);
|
||||
test_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
test_cleanup:
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
curl_slist_free_all(hhl);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
Loading…
Reference in New Issue
Block a user