mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-25 04:09:31 +03:00
expand PP test a bit
This commit is contained in:
@@ -155,6 +155,29 @@ struct MHDT_PostInstructions
|
||||
*/
|
||||
enum MHD_HTTP_PostEncoding enc;
|
||||
|
||||
/**
|
||||
* Data to be POSTed to the server.
|
||||
*/
|
||||
const char *postdata;
|
||||
|
||||
/**
|
||||
* HTTP header to set POST content encoding, use
|
||||
* NULL if you want to set @e request_hdr directly.
|
||||
*/
|
||||
const char *postheader;
|
||||
|
||||
/**
|
||||
* HTTP header values for the request, automatically
|
||||
* updated to include @e postheader.
|
||||
*/
|
||||
struct curl_slist *request_hdr;
|
||||
|
||||
/**
|
||||
* Number of bytes in @e postdata, use 0 for
|
||||
* 0-terminated @e postdata.
|
||||
*/
|
||||
size_t postdata_size;
|
||||
|
||||
/**
|
||||
* size to use for the buffer.
|
||||
*/
|
||||
|
||||
@@ -574,12 +574,6 @@ MHDT_client_do_post (
|
||||
const struct MHDT_PhaseContext *pc)
|
||||
{
|
||||
struct MHDT_PostInstructions *pi = cls;
|
||||
const char *text = "fixme";
|
||||
struct ReadBuffer rb = {
|
||||
.buf = text,
|
||||
.len = strlen (text),
|
||||
.chunks = 2
|
||||
};
|
||||
CURL *c;
|
||||
|
||||
c = curl_easy_init ();
|
||||
@@ -595,27 +589,44 @@ MHDT_client_do_post (
|
||||
}
|
||||
if (CURLE_OK !=
|
||||
curl_easy_setopt (c,
|
||||
CURLOPT_UPLOAD,
|
||||
CURLOPT_POST,
|
||||
1L))
|
||||
{
|
||||
curl_easy_cleanup (c);
|
||||
return "Failed to set PUT method for curl request";
|
||||
return "Failed to set POST method for curl request";
|
||||
}
|
||||
if (CURLE_OK !=
|
||||
curl_easy_setopt (c,
|
||||
CURLOPT_READFUNCTION,
|
||||
&read_cb))
|
||||
CURLOPT_POSTFIELDS,
|
||||
pi->postdata))
|
||||
{
|
||||
curl_easy_cleanup (c);
|
||||
return "Failed to set READFUNCTION for curl request";
|
||||
return "Failed to set POSTFIELDS for curl request";
|
||||
}
|
||||
if (0 != pi->postdata_size)
|
||||
{
|
||||
if (CURLE_OK !=
|
||||
curl_easy_setopt (c,
|
||||
CURLOPT_POSTFIELDSIZE_LARGE,
|
||||
(curl_off_t) pi->postdata_size))
|
||||
{
|
||||
curl_easy_cleanup (c);
|
||||
return "Failed to set POSTFIELDS for curl request";
|
||||
}
|
||||
}
|
||||
if (NULL != pi->postheader)
|
||||
{
|
||||
pi->request_hdr = curl_slist_append (pi->request_hdr,
|
||||
pi->postheader);
|
||||
pi->postheader = NULL;
|
||||
}
|
||||
if (CURLE_OK !=
|
||||
curl_easy_setopt (c,
|
||||
CURLOPT_READDATA,
|
||||
&rb))
|
||||
CURLOPT_HTTPHEADER,
|
||||
pi->request_hdr))
|
||||
{
|
||||
curl_easy_cleanup (c);
|
||||
return "Failed to set READFUNCTION for curl request";
|
||||
return "Failed to set HTTPHEADER for curl request";
|
||||
}
|
||||
PERFORM_REQUEST (c);
|
||||
CHECK_STATUS (c,
|
||||
|
||||
@@ -56,6 +56,35 @@ main (int argc, char *argv[])
|
||||
};
|
||||
struct MHDT_PostInstructions simple_pi = {
|
||||
.enc = MHD_HTTP_POST_ENCODING_FORM_URLENCODED,
|
||||
.postdata = "V1=One&V2=Two",
|
||||
.postheader = "application/x-www-form-urlencoded",
|
||||
.buffer_size = 32,
|
||||
.auto_stream_size = 16
|
||||
};
|
||||
struct MHDT_PostInstructions simple_mp = {
|
||||
.enc = MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA,
|
||||
.postdata = "--{boundary string}\n"
|
||||
"Content-Disposition: form-data; name=\"username\",\n"
|
||||
"\n"
|
||||
"Bob\n"
|
||||
"--XXXX\n"
|
||||
"Content-Disposition: form-data; name=\"password\",\n"
|
||||
"\n"
|
||||
"Passwo3d\n"
|
||||
"--XXXX\n"
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"image.jpg\"\n"
|
||||
"Content-Type: image/jpeg,\n"
|
||||
"\n"
|
||||
"IMAGEDATA"
|
||||
"--XXXX--\n",
|
||||
.postheader = "multipart/form-data; boundary=XXXX",
|
||||
.buffer_size = 32,
|
||||
.auto_stream_size = 16
|
||||
};
|
||||
struct MHDT_PostInstructions simple_tp = {
|
||||
.enc = MHD_HTTP_POST_ENCODING_TEXT_PLAIN,
|
||||
.postdata = "V1=One\r\nV2=Two\r\n",
|
||||
.postheader = "text/plain",
|
||||
.buffer_size = 32,
|
||||
.auto_stream_size = 16
|
||||
};
|
||||
@@ -68,6 +97,22 @@ main (int argc, char *argv[])
|
||||
.client_cb_cls = &simple_pi,
|
||||
.timeout_ms = 2500,
|
||||
},
|
||||
{
|
||||
.label = "multipart post",
|
||||
.server_cb = &MHDT_server_reply_check_post,
|
||||
.server_cb_cls = &simple_mp,
|
||||
.client_cb = &MHDT_client_do_post,
|
||||
.client_cb_cls = &simple_mp,
|
||||
.timeout_ms = 2500,
|
||||
},
|
||||
{
|
||||
.label = "plain text post",
|
||||
.server_cb = &MHDT_server_reply_check_post,
|
||||
.server_cb_cls = &simple_tp,
|
||||
.client_cb = &MHDT_client_do_post,
|
||||
.client_cb_cls = &simple_tp,
|
||||
.timeout_ms = 2500,
|
||||
},
|
||||
{
|
||||
.label = NULL,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user