From 1e8c421d66b2ac61dff723f150e3cc927863b599 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 12 Sep 2020 13:55:27 -0700 Subject: [PATCH] formatting --- ixwebsocket/IXHttp.cpp | 25 ++++++++++++++----------- test/IXHttpServerTest.cpp | 21 ++++++++++++--------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/ixwebsocket/IXHttp.cpp b/ixwebsocket/IXHttp.cpp index 62c60422..5648c284 100644 --- a/ixwebsocket/IXHttp.cpp +++ b/ixwebsocket/IXHttp.cpp @@ -129,24 +129,27 @@ namespace ix { return std::make_tuple(false, "Error parsing HTTP headers", httpRequest); } - + 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; } } diff --git a/test/IXHttpServerTest.cpp b/test/IXHttpServerTest.cpp index bbdb3295..2d7993d1 100644 --- a/test/IXHttpServerTest.cpp +++ b/test/IXHttpServerTest.cpp @@ -69,14 +69,17 @@ TEST_CASE("http server", "[httpd]") int port = getFreePort(); ix::HttpServer server(port, "127.0.0.1"); - server.setOnConnectionCallback([](HttpRequestPtr request, std::shared_ptr) -> HttpResponsePtr { - if (request->method == "POST"){ - return std::make_shared(200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), request->body); - } - - return std::make_shared(400, "BAD REQUEST"); - }); - + server.setOnConnectionCallback( + [](HttpRequestPtr request, std::shared_ptr) -> HttpResponsePtr { + if (request->method == "POST") + { + return std::make_shared( + 200, "OK", HttpErrorCode::Ok, WebSocketHttpHeaders(), request->body); + } + + return std::make_shared(400, "BAD REQUEST"); + }); + auto res = server.listen(); REQUIRE(res.first); server.start(); @@ -97,7 +100,7 @@ TEST_CASE("http server", "[httpd]") args->body = "Hello World!"; auto response = httpClient.post(url, args->body, args); - + std::cerr << "Status: " << response->statusCode << std::endl; std::cerr << "Error message: " << response->errorMsg << std::endl; std::cerr << "Payload: " << response->payload << std::endl;