diff options
| author | Dan Engelbrecht <[email protected]> | 2026-02-12 15:25:05 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-02-12 15:25:05 +0100 |
| commit | 3a563f5e8fcabffe686e1deb5862bdf39078ebdf (patch) | |
| tree | 91a027f026f2c46a0e406d2203aea9bf60ae2dc8 /src/zenhttp/httpclient.cpp | |
| parent | add simple http client tests (#751) (diff) | |
| download | zen-3a563f5e8fcabffe686e1deb5862bdf39078ebdf.tar.xz zen-3a563f5e8fcabffe686e1deb5862bdf39078ebdf.zip | |
add IsLocalMachineRequest to HttpServerRequest (#749)
* add IsLocalMachineRequest to HttpServerRequest
Diffstat (limited to 'src/zenhttp/httpclient.cpp')
| -rw-r--r-- | src/zenhttp/httpclient.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp index 0544bf5c8..c77be8624 100644 --- a/src/zenhttp/httpclient.cpp +++ b/src/zenhttp/httpclient.cpp @@ -402,7 +402,14 @@ TEST_CASE("httpclient") { if (HttpServiceRequest.RelativeUri() == "yo") { - return HttpServiceRequest.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, "hey man"); + if (HttpServiceRequest.IsLocalMachineRequest()) + { + return HttpServiceRequest.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, "hey family"); + } + else + { + return HttpServiceRequest.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, "hey stranger"); + } } return HttpServiceRequest.WriteResponse(HttpResponseCode::OK); } @@ -440,6 +447,7 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } if (IsIPv6Capable()) @@ -452,6 +460,7 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } { @@ -463,6 +472,7 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } # if 0 { @@ -474,7 +484,9 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } + Sleep(20000); # endif // 0 AsioServer->RequestExit(); } @@ -483,7 +495,7 @@ TEST_CASE("httpclient") # if ZEN_PLATFORM_WINDOWS SUBCASE("httpsys") { - Ref<HttpServer> HttpSysServer = CreateHttpSysServer(HttpSysConfig{.ForceLoopback = true}); + Ref<HttpServer> HttpSysServer = CreateHttpSysServer(HttpSysConfig{.ForceLoopback = false}); int Port = HttpSysServer->Initialize(7575, TmpDir.Path()); REQUIRE(Port != -1); @@ -511,6 +523,7 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } if (IsIPv6Capable()) @@ -523,6 +536,7 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } { @@ -534,6 +548,7 @@ TEST_CASE("httpclient") HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } # if 0 { @@ -543,9 +558,11 @@ TEST_CASE("httpclient") ZEN_INFO("Request using {}", Client.GetBaseUri()); - HttpClient::Response TestResponse = Client.Get("/test"); + HttpClient::Response TestResponse = Client.Get("/test/yo"); CHECK(TestResponse.IsSuccess()); + CHECK_EQ(TestResponse.AsText(), "hey family"); } + Sleep(20000); # endif // 0 HttpSysServer->RequestExit(); } |