(http client + server + ws) Add support for uploading files with ws -F foo=@filename, new -D http server option to debug incoming client requests, internal api changed for http POST, PUT and PATCH to supply an HttpFormDataParameters

This commit is contained in:
Benjamin Sergeant
2020-10-08 12:43:18 -07:00
parent 032ed9af9c
commit fa0408e70b
8 changed files with 183 additions and 43 deletions

View File

@ -555,9 +555,21 @@ namespace ix
HttpResponsePtr HttpClient::post(const std::string& url,
const HttpParameters& httpParameters,
const HttpFormDataParameters& httpFormDataParameters,
HttpRequestArgsPtr args)
{
return request(url, kPost, serializeHttpParameters(httpParameters), args);
if (httpFormDataParameters.empty())
{
return request(url, kPost, serializeHttpParameters(httpParameters), args);
}
else
{
std::string multipartBoundary = generateMultipartBoundary();
args->multipartBoundary = multipartBoundary;
std::string body = serializeHttpFormDataParameters(
multipartBoundary, httpFormDataParameters, httpParameters);
return request(url, kPost, body, args);
}
}
HttpResponsePtr HttpClient::post(const std::string& url,
@ -569,9 +581,21 @@ namespace ix
HttpResponsePtr HttpClient::put(const std::string& url,
const HttpParameters& httpParameters,
const HttpFormDataParameters& httpFormDataParameters,
HttpRequestArgsPtr args)
{
return request(url, kPut, serializeHttpParameters(httpParameters), args);
if (httpFormDataParameters.empty())
{
return request(url, kPut, serializeHttpParameters(httpParameters), args);
}
else
{
std::string multipartBoundary = generateMultipartBoundary();
args->multipartBoundary = multipartBoundary;
std::string body = serializeHttpFormDataParameters(
multipartBoundary, httpFormDataParameters, httpParameters);
return request(url, kPut, body, args);
}
}
HttpResponsePtr HttpClient::put(const std::string& url,
@ -583,9 +607,21 @@ namespace ix
HttpResponsePtr HttpClient::patch(const std::string& url,
const HttpParameters& httpParameters,
const HttpFormDataParameters& httpFormDataParameters,
HttpRequestArgsPtr args)
{
return request(url, kPatch, serializeHttpParameters(httpParameters), args);
if (httpFormDataParameters.empty())
{
return request(url, kPatch, serializeHttpParameters(httpParameters), args);
}
else
{
std::string multipartBoundary = generateMultipartBoundary();
args->multipartBoundary = multipartBoundary;
std::string body = serializeHttpFormDataParameters(
multipartBoundary, httpFormDataParameters, httpParameters);
return request(url, kPatch, body, args);
}
}
HttpResponsePtr HttpClient::patch(const std::string& url,