formatting
This commit is contained in:
parent
72d6651ded
commit
1e8c421d66
@ -131,22 +131,25 @@ namespace ix
|
||||
}
|
||||
|
||||
std::string body = "";
|
||||
if (headers.find("Content-Length") != headers.end()){
|
||||
|
||||
if (headers.find("Content-Length") != headers.end())
|
||||
{
|
||||
int contentLength = 0;
|
||||
try {
|
||||
try
|
||||
{
|
||||
contentLength = std::stoi(headers["Content-Length"]);
|
||||
}
|
||||
catch (std::exception){
|
||||
return std::make_tuple(false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
|
||||
catch (std::exception)
|
||||
{
|
||||
return std::make_tuple(
|
||||
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
|
||||
}
|
||||
|
||||
char c;
|
||||
body.reserve(contentLength);
|
||||
|
||||
for (int i = 0; i < contentLength; i++){
|
||||
if (socket->readByte(&c, isCancellationRequested))
|
||||
body += c;
|
||||
for (int i = 0; i < contentLength; i++)
|
||||
{
|
||||
if (socket->readByte(&c, isCancellationRequested)) body += c;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,12 @@ TEST_CASE("http server", "[httpd]")
|
||||
int port = getFreePort();
|
||||
ix::HttpServer server(port, "127.0.0.1");
|
||||
|
||||
server.setOnConnectionCallback([](HttpRequestPtr request, std::shared_ptr<ConnectionState>) -> HttpResponsePtr {
|
||||
if (request->method == "POST"){
|
||||
return std::make_shared<HttpResponse>(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), request->body);
|
||||
server.setOnConnectionCallback(
|
||||
[](HttpRequestPtr request, std::shared_ptr<ConnectionState>) -> HttpResponsePtr {
|
||||
if (request->method == "POST")
|
||||
{
|
||||
return std::make_shared<HttpResponse>(
|
||||
200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), request->body);
|
||||
}
|
||||
|
||||
return std::make_shared<HttpResponse>(400, "BAD REQUEST");
|
||||
|
Loading…
Reference in New Issue
Block a user