-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP POST request #15
Comments
@jl2378, thanks for the report! Do you mean POST requests are much slower than GET requests? As you can see in the code, both implementations are almost same except the following POST specific code in if (req.method == "POST") {
if (!detail::read_content(strm, req)) {
// TODO:
return;
}
static std::string type = "application/x-www-form-urlencoded";
if (!req.get_header_value("Content-Type").compare(0, type.size(), type)) {
detail::parse_query_text(req.body, req.params);
}
} It's so simple, right? I have personally never had such a performance issues on my Windows box. So I am really curious why the problem happenes on your environment. Please let me know more detailed information regarding the performance issue. |
Oops... Reopen it again. |
It could be. In order to understand the situation more, I made the sample code to measure each post request time. #include <httplib.h>
#include <chrono>
#include <iostream>
using namespace std;
struct StopWatch {
StopWatch(const string& label) : label_(label) {
start_ = chrono::system_clock::now();
}
~StopWatch() {
auto end = chrono::system_clock::now();
auto diff = end - start_;
auto count = chrono::duration_cast<chrono::milliseconds>(diff).count();
cout << label_ << ": " << count << " millisec." << endl;
}
string label_;
chrono::system_clock::time_point start_;
};
int main(int argc, char* argv[]) {
string body(1024 * 5, 'a');
httplib::Client cli("httpbin.org", 80);
for (int i = 0; i < 3; i++) {
StopWatch sw(to_string(i).c_str());
auto res = cli.post("/post", body, "application/octet-stream");
assert(res->status == 200);
}
return 0;
} When I run it on my Windows box, I got the following result:
It works pretty good on my machine. What result do you get with the code on your machine? Thanks for your help! |
Please let me know if it is still an issue with you. |
I am getting a very slow response also. But it is all messages, not just POST.
Running on windows under Visual Studio 2019. Both debug and release modes. I get about 1 second per message I send in a loop. On the server, looking at the req object passed to the log using the debugger, Also, perhaps a separate issue, I noticed that if I send a POST with a body, the req argument in the server's log function never contains the body. The body field is always empty. Yet I know it arrive at the server because the handler processes it.
Where 'config' is a string containing a JSON encoded structure of about 500 bytes. The handler matches "/network". |
Thanks for the report. But I still cannot reproduce the slow connection/reading problem...
As you see, 1st time is decent. 2nd time is super fast. I would like to know what you get with the benchmark. Could you try it when you have time? By this, we can at least check if the problem happens on the client side. I am really curious about When it comes to the logging, I cannot reproduce it either. Here is my test result:
Could you try the above to see if you get the same result? Thanks for your help! |
I will create a separate issue for this. |
Thanks for the fast response. The speed problem remains. I moved it to #366 |
POST requests are extremely slow. Each request is taking about 1 second to complete. I am using the library on windows.
The text was updated successfully, but these errors were encountered: