add PATCH and add option to enforce a http request body write (#195)
* add PATCH and add option to enforce a http request body write * remove private bool prop
This commit is contained in:
parent
2786631e3b
commit
8760c87635
@ -25,6 +25,7 @@ namespace ix
|
|||||||
const std::string HttpClient::kHead = "HEAD";
|
const std::string HttpClient::kHead = "HEAD";
|
||||||
const std::string HttpClient::kDel = "DEL";
|
const std::string HttpClient::kDel = "DEL";
|
||||||
const std::string HttpClient::kPut = "PUT";
|
const std::string HttpClient::kPut = "PUT";
|
||||||
|
const std::string HttpClient::kPatch = "PATCH";
|
||||||
|
|
||||||
HttpClient::HttpClient(bool async)
|
HttpClient::HttpClient(bool async)
|
||||||
: _async(async)
|
: _async(async)
|
||||||
@ -49,6 +50,9 @@ namespace ix
|
|||||||
_tlsOptions = tlsOptions;
|
_tlsOptions = tlsOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setForceBody(bool value) {
|
||||||
|
_forceBody = value;
|
||||||
|
}
|
||||||
HttpRequestArgsPtr HttpClient::createRequest(const std::string& url, const std::string& verb)
|
HttpRequestArgsPtr HttpClient::createRequest(const std::string& url, const std::string& verb)
|
||||||
{
|
{
|
||||||
auto request = std::make_shared<HttpRequestArgs>();
|
auto request = std::make_shared<HttpRequestArgs>();
|
||||||
@ -192,7 +196,7 @@ namespace ix
|
|||||||
ss << "User-Agent: " << userAgent() << "\r\n";
|
ss << "User-Agent: " << userAgent() << "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verb == kPost || verb == kPut)
|
if (verb == kPost || verb == kPut || verb == kPatch || _forceBody)
|
||||||
{
|
{
|
||||||
ss << "Content-Length: " << body.size() << "\r\n";
|
ss << "Content-Length: " << body.size() << "\r\n";
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ namespace ix
|
|||||||
const std::string& body,
|
const std::string& body,
|
||||||
HttpRequestArgsPtr args,
|
HttpRequestArgsPtr args,
|
||||||
int redirects = 0);
|
int redirects = 0);
|
||||||
|
void setForceBody(bool value);
|
||||||
// Async API
|
// Async API
|
||||||
HttpRequestArgsPtr createRequest(const std::string& url = std::string(),
|
HttpRequestArgsPtr createRequest(const std::string& url = std::string(),
|
||||||
const std::string& verb = HttpClient::kGet);
|
const std::string& verb = HttpClient::kGet);
|
||||||
@ -78,15 +78,16 @@ namespace ix
|
|||||||
const static std::string kHead;
|
const static std::string kHead;
|
||||||
const static std::string kDel;
|
const static std::string kDel;
|
||||||
const static std::string kPut;
|
const static std::string kPut;
|
||||||
|
const static std::string kPatch;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void log(const std::string& msg, HttpRequestArgsPtr args);
|
void log(const std::string& msg, HttpRequestArgsPtr args);
|
||||||
|
|
||||||
bool gzipInflate(const std::string& in, std::string& out);
|
bool gzipInflate(const std::string& in, std::string& out);
|
||||||
|
bool _forceBody;
|
||||||
|
|
||||||
// Async API background thread runner
|
// Async API background thread runner
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
// Async API
|
// Async API
|
||||||
bool _async;
|
bool _async;
|
||||||
std::queue<std::pair<HttpRequestArgsPtr, OnResponseCallback>> _queue;
|
std::queue<std::pair<HttpRequestArgsPtr, OnResponseCallback>> _queue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user