diff --git a/ballerina-tests/http-advanced-tests/Ballerina.toml b/ballerina-tests/http-advanced-tests/Ballerina.toml index bced83ca5a..0c990559fd 100644 --- a/ballerina-tests/http-advanced-tests/Ballerina.toml +++ b/ballerina-tests/http-advanced-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_advanced_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-advanced-tests/Dependencies.toml b/ballerina-tests/http-advanced-tests/Dependencies.toml index fba5562219..b12ab29881 100644 --- a/ballerina-tests/http-advanced-tests/Dependencies.toml +++ b/ballerina-tests/http-advanced-tests/Dependencies.toml @@ -72,7 +72,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -105,7 +105,7 @@ modules = [ [[package]] org = "ballerina" name = "http_advanced_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "file"}, @@ -125,7 +125,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-client-tests/Ballerina.toml b/ballerina-tests/http-client-tests/Ballerina.toml index 0d61d68e73..296935bd60 100644 --- a/ballerina-tests/http-client-tests/Ballerina.toml +++ b/ballerina-tests/http-client-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_client_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-client-tests/Dependencies.toml b/ballerina-tests/http-client-tests/Dependencies.toml index 53d1db7187..6f631cf8cb 100644 --- a/ballerina-tests/http-client-tests/Dependencies.toml +++ b/ballerina-tests/http-client-tests/Dependencies.toml @@ -69,7 +69,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_client_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-client-tests/tests/http_client_host_header_test.bal b/ballerina-tests/http-client-tests/tests/http_client_host_header_test.bal index a81562d92d..ff28d2e35e 100644 --- a/ballerina-tests/http-client-tests/tests/http_client_host_header_test.bal +++ b/ballerina-tests/http-client-tests/tests/http_client_host_header_test.bal @@ -129,3 +129,179 @@ function testHttp2ClientHostHeader3() returns error? { host = check http2ClientHost2->post("/host", req, {"Host": "mock3.com"}); test:assertEquals(host, "mock3.com"); } + +service /api on new http:Listener(passthroughHostTestPort1) { + + resource function 'default [string test]/host(@http:Header string host) returns string { + return host; + } +} + +final http:Client httpHostPassthroughClientEP = check new (string `localhost:${passthroughHostTestPort1}`, httpVersion = http:HTTP_1_1); +final http:Client http2HostPassthroughClientEP = check new (string `localhost:${passthroughHostTestPort1}`); +final http:Client http2HostPassthroughClientEPWithPriorKnowledge = check new (string `localhost:${passthroughHostTestPort1}`, http2Settings = {http2PriorKnowledge: true}); + +final http:Client httpHostPassthroughTestClient = check new (string `localhost:${passthroughHostTestPort2}`); + +service /api on new http:Listener(passthroughHostTestPort2) { + + resource function get http/host(http:Request req) returns http:Response|error { + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req); + } + + resource function get http2/host(http:Request req) returns http:Response|error { + return http2HostPassthroughClientEP->execute(req.method, req.rawPath, req); + } + + resource function get http2prior/host(http:Request req) returns http:Response|error { + return http2HostPassthroughClientEPWithPriorKnowledge->execute(req.method, req.rawPath, req); + } + + resource function get update1/host(string host, http:Request req) returns http:Response|error { + req.setHeader("Host", host); + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req); + } + + resource function get update2/host(string host, http:Request req) returns http:Response|error { + req.setHeader("host", host); + return http2HostPassthroughClientEP->execute(req.method, req.rawPath, req); + } + + resource function get update3/host(string host, http:Request req) returns http:Response|error { + req.setHeader("HOST", host); + return http2HostPassthroughClientEPWithPriorKnowledge->execute(req.method, req.rawPath, req); + } + + resource function get update4/host(string host, http:Request req) returns http:Response|error { + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req, {host: host}); + } + + resource function get update5/host(string host, http:Request req) returns http:Response|error { + return http2HostPassthroughClientEP->execute(req.method, req.rawPath, req, {host: host}); + } + + resource function get update6/host(string host, http:Request req) returns http:Response|error { + return http2HostPassthroughClientEPWithPriorKnowledge->execute(req.method, req.rawPath, req, {host: host}); + } + + resource function get update7/host(string host, http:Request req) returns http:Response|error { + return httpHostPassthroughClientEP->post(req.rawPath, req, {host: host}); + } + + resource function get update8/host(string host, http:Request req) returns http:Response|error { + return http2HostPassthroughClientEP->post(req.rawPath, req, {host: host}); + } + + resource function get update9/host(string host, http:Request req) returns http:Response|error { + return http2HostPassthroughClientEPWithPriorKnowledge->post(req.rawPath, req, {host: host}); + } + + resource function get update10/host(string host, http:Request req) returns http:Response|error { + return httpHostPassthroughClientEP->/api/test/host.post(req, {host: host}); + } + + resource function get update11/host(string host, http:Request req) returns http:Response|error { + return http2HostPassthroughClientEP->/api/test/host.post(req, {host: host}); + } + + resource function get update12/host(string host, http:Request req) returns http:Response|error { + return http2HostPassthroughClientEPWithPriorKnowledge->/api/test/host.post(req, {host: host}); + } + + resource function get negative1/host(string host, http:Request req) returns http:Response|error { + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req, {host123: host}); + } + + resource function get negative2/host(string host, http:Request req) returns http:Response|error { + req.setHeader("X-Host", host); + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req); + } + + resource function get negative3/host(string host, http:Request req) returns http:Response|error { + req.setHeader("Host", host); + req.removeHeader("Host"); + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req); + } + + resource function get negative4/host(string host, http:Request req) returns http:Response|error { + req.setHeader("Host", host); + req.removeHeader("Host"); + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req, {host: "random.com"}); + } + + resource function get negative5/host(string host, http:Request req) returns http:Response|error { + req.setHeader("Host", host); + req.removeHeader("Host"); + req.setHeader("Host", "random.com"); + return httpHostPassthroughClientEP->execute(req.method, req.rawPath, req); + } +} + +@test:Config {} +function testHostHeaderInPassthrough() returns error? { + string host = check httpHostPassthroughTestClient->/api/http/host.get(); + test:assertEquals(host, "localhost:9607", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/http2/host.get(); + test:assertEquals(host, "localhost:9607", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/http2prior/host.get(); + test:assertEquals(host, "localhost:9607", "Invalid host header in passthrough"); +} + +@test:Config {} +function testUpdateHostHeaderInPassthrough() returns error? { + string host = check httpHostPassthroughTestClient->/api/update1/host.get(host = "random-update-1.com"); + test:assertEquals(host, "random-update-1.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update2/host.get(host = "random-update-2.com"); + test:assertEquals(host, "random-update-2.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update3/host.get(host = "random-update-3.com"); + test:assertEquals(host, "random-update-3.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update4/host.get(host = "random-update-4.com"); + test:assertEquals(host, "random-update-4.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update5/host.get(host = "random-update-5.com"); + test:assertEquals(host, "random-update-5.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update6/host.get(host = "random-update-6.com"); + test:assertEquals(host, "random-update-6.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update7/host.get(host = "random-update-7.com"); + test:assertEquals(host, "random-update-7.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update8/host.get(host = "random-update-8.com"); + test:assertEquals(host, "random-update-8.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update9/host.get(host = "random-update-9.com"); + test:assertEquals(host, "random-update-9.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update10/host.get(host = "random-update-10.com"); + test:assertEquals(host, "random-update-10.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update11/host.get(host = "random-update-11.com"); + test:assertEquals(host, "random-update-11.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/update12/host.get(host = "random-update-12.com"); + test:assertEquals(host, "random-update-12.com", "Invalid host header in passthrough"); +} + +@test:Config {} +function testNegativeCasesInPassthrough() returns error? { + string host = check httpHostPassthroughTestClient->/api/negative1/host.get(host = "random-update-1.com"); + test:assertEquals(host, "localhost:9607", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/negative2/host.get(host = "random-update-2.com"); + test:assertEquals(host, "localhost:9607", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/negative3/host.get(host = "random-update-3.com"); + test:assertEquals(host, "localhost:9607", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/negative4/host.get(host = "random-update-4.com"); + test:assertEquals(host, "random.com", "Invalid host header in passthrough"); + + host = check httpHostPassthroughTestClient->/api/negative5/host.get(host = "random-update-5.com"); + test:assertEquals(host, "random.com", "Invalid host header in passthrough"); +} diff --git a/ballerina-tests/http-client-tests/tests/test_service_ports.bal b/ballerina-tests/http-client-tests/tests/test_service_ports.bal index fce33b93e3..706826a252 100644 --- a/ballerina-tests/http-client-tests/tests/test_service_ports.bal +++ b/ballerina-tests/http-client-tests/tests/test_service_ports.bal @@ -35,3 +35,5 @@ const int clientFormUrlEncodedTestPort = 9604; const int http2ClientHostHeaderTestPort = 9605; const int httpClientHostHeaderTestPort = 9606; +const int passthroughHostTestPort1 = 9607; +const int passthroughHostTestPort2 = 9608; diff --git a/ballerina-tests/http-dispatching-tests/Ballerina.toml b/ballerina-tests/http-dispatching-tests/Ballerina.toml index 2a1e9dac66..28f6b075cd 100644 --- a/ballerina-tests/http-dispatching-tests/Ballerina.toml +++ b/ballerina-tests/http-dispatching-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_dispatching_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-dispatching-tests/Dependencies.toml b/ballerina-tests/http-dispatching-tests/Dependencies.toml index 8cee8e427d..919c23871e 100644 --- a/ballerina-tests/http-dispatching-tests/Dependencies.toml +++ b/ballerina-tests/http-dispatching-tests/Dependencies.toml @@ -69,7 +69,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_dispatching_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -124,7 +124,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-interceptor-tests/Ballerina.toml b/ballerina-tests/http-interceptor-tests/Ballerina.toml index be73a4eca6..16ce1a471b 100644 --- a/ballerina-tests/http-interceptor-tests/Ballerina.toml +++ b/ballerina-tests/http-interceptor-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_interceptor_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-interceptor-tests/Dependencies.toml b/ballerina-tests/http-interceptor-tests/Dependencies.toml index 7740b8e7c0..bddf9320a6 100644 --- a/ballerina-tests/http-interceptor-tests/Dependencies.toml +++ b/ballerina-tests/http-interceptor-tests/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_interceptor_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -115,7 +115,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-misc-tests/Ballerina.toml b/ballerina-tests/http-misc-tests/Ballerina.toml index e83d874577..b235354aff 100644 --- a/ballerina-tests/http-misc-tests/Ballerina.toml +++ b/ballerina-tests/http-misc-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_misc_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-misc-tests/Dependencies.toml b/ballerina-tests/http-misc-tests/Dependencies.toml index 3f163ea1de..3694c12d7b 100644 --- a/ballerina-tests/http-misc-tests/Dependencies.toml +++ b/ballerina-tests/http-misc-tests/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_misc_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -118,7 +118,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-resiliency-tests/Ballerina.toml b/ballerina-tests/http-resiliency-tests/Ballerina.toml index 8850e069cf..e4489623a3 100644 --- a/ballerina-tests/http-resiliency-tests/Ballerina.toml +++ b/ballerina-tests/http-resiliency-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_resiliency_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-resiliency-tests/Dependencies.toml b/ballerina-tests/http-resiliency-tests/Dependencies.toml index 214da3b7ae..e5e0819c92 100644 --- a/ballerina-tests/http-resiliency-tests/Dependencies.toml +++ b/ballerina-tests/http-resiliency-tests/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_resiliency_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -116,7 +116,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-security-tests/Ballerina.toml b/ballerina-tests/http-security-tests/Ballerina.toml index 232b2f50e1..d4c501c598 100644 --- a/ballerina-tests/http-security-tests/Ballerina.toml +++ b/ballerina-tests/http-security-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_security_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-security-tests/Dependencies.toml b/ballerina-tests/http-security-tests/Dependencies.toml index 974fec2ef3..f36b8cd930 100644 --- a/ballerina-tests/http-security-tests/Dependencies.toml +++ b/ballerina-tests/http-security-tests/Dependencies.toml @@ -69,7 +69,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_security_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "http"}, @@ -120,7 +120,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-service-tests/Ballerina.toml b/ballerina-tests/http-service-tests/Ballerina.toml index 6418898f3a..aa7093df30 100644 --- a/ballerina-tests/http-service-tests/Ballerina.toml +++ b/ballerina-tests/http-service-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_service_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http-service-tests/Dependencies.toml b/ballerina-tests/http-service-tests/Dependencies.toml index 6cbc5578f4..33a35553c9 100644 --- a/ballerina-tests/http-service-tests/Dependencies.toml +++ b/ballerina-tests/http-service-tests/Dependencies.toml @@ -69,7 +69,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_service_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-test-common/Ballerina.toml b/ballerina-tests/http-test-common/Ballerina.toml index 8b194c15c5..1c0b1310ce 100644 --- a/ballerina-tests/http-test-common/Ballerina.toml +++ b/ballerina-tests/http-test-common/Ballerina.toml @@ -1,4 +1,4 @@ [package] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" diff --git a/ballerina-tests/http-test-common/Dependencies.toml b/ballerina-tests/http-test-common/Dependencies.toml index a00aa03c66..0f18fe51e9 100644 --- a/ballerina-tests/http-test-common/Dependencies.toml +++ b/ballerina-tests/http-test-common/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.8.0" [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "lang.string"}, {org = "ballerina", name = "mime"}, diff --git a/ballerina-tests/http2-tests/Ballerina.toml b/ballerina-tests/http2-tests/Ballerina.toml index 62c4b7962d..62a23e1bf7 100644 --- a/ballerina-tests/http2-tests/Ballerina.toml +++ b/ballerina-tests/http2-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http2_tests" -version = "2.10.10" +version = "2.10.11" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.10.10" +version = "2.10.11" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.10.10.jar" +path = "../../test-utils/build/libs/http-test-utils-2.10.11-SNAPSHOT.jar" diff --git a/ballerina-tests/http2-tests/Dependencies.toml b/ballerina-tests/http2-tests/Dependencies.toml index 2cb4a625d3..2fc6e4c534 100644 --- a/ballerina-tests/http2-tests/Dependencies.toml +++ b/ballerina-tests/http2-tests/Dependencies.toml @@ -69,7 +69,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http2_tests" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.10.10" +version = "2.10.11" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 8fdd4b85cb..3b8c78e53d 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" authors = ["Ballerina"] keywords = ["http", "network", "service", "listener", "client"] repository = "https://github.com/ballerina-platform/module-ballerina-http" @@ -16,8 +16,8 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "http-native" -version = "2.10.10" -path = "../native/build/libs/http-native-2.10.10.jar" +version = "2.10.11" +path = "../native/build/libs/http-native-2.10.11-SNAPSHOT.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 49688e96f9..f168d5088c 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "http-compiler-plugin" class = "io.ballerina.stdlib.http.compiler.HttpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/http-compiler-plugin-2.10.10.jar" +path = "../compiler-plugin/build/libs/http-compiler-plugin-2.10.11-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 2b177c334c..9266f2fa63 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -25,7 +25,7 @@ modules = [ [[package]] org = "ballerina" name = "cache" -version = "3.7.0" +version = "3.7.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, @@ -76,7 +76,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.10.10" +version = "2.10.11" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -283,7 +283,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.2.0" +version = "1.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] diff --git a/changelog.md b/changelog.md index 505e055d65..0578df7694 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,12 @@ This file contains all the notable changes done to the Ballerina HTTP package th The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- [Update Host header only when a value is intentionally provided](https://github.com/ballerina-platform/ballerina-library/issues/6149) + ## [2.10.8] - 2024-03-05 ### Added diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java b/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java index 233f3e2312..b31d83f132 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/HttpConstants.java @@ -238,6 +238,7 @@ public final class HttpConstants { public static final int NO_CONTENT_LENGTH_FOUND = -1; public static final short ONE_BYTE = 1; public static final String HTTP_HEADERS = "http_headers"; + public static final String SET_HOST_HEADER = "set_host_header"; public static final String HTTP_TRAILER_HEADERS = "http_trailer_headers"; public static final String LEADING_HEADER = "leading"; public static final BString HEADER_REQUEST_FIELD = StringUtils.fromString("request"); diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/AbstractHTTPAction.java b/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/AbstractHTTPAction.java index 64bb9c8f0a..b4b718cf24 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/AbstractHTTPAction.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/AbstractHTTPAction.java @@ -66,9 +66,11 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.Objects; import static io.ballerina.runtime.api.constants.RuntimeConstants.BALLERINA_VERSION; import static io.ballerina.stdlib.http.api.HttpConstants.ANN_CONFIG_ATTR_COMPRESSION; +import static io.ballerina.stdlib.http.api.HttpConstants.SET_HOST_HEADER; import static io.ballerina.stdlib.http.api.HttpUtil.extractEntity; import static io.ballerina.stdlib.http.api.HttpUtil.getCompressionState; import static io.ballerina.stdlib.http.transport.contract.Constants.ENCODING_DEFLATE; @@ -93,7 +95,7 @@ protected static HttpCarbonMessage createOutboundRequestMsg(String serviceUri, B HttpCarbonMessage requestMsg = HttpUtil.getCarbonMsg(request, HttpUtil.createHttpCarbonMessage(true)); HttpUtil.checkEntityAvailability(request); HttpUtil.enrichOutboundMessage(requestMsg, request); - prepareOutboundRequest(serviceUri, path, requestMsg, isNoEntityBodyRequest(request)); + prepareOutboundRequest(serviceUri, path, requestMsg, isNoEntityBodyRequest(request), isHostHeaderSet(request)); handleAcceptEncodingHeader(requestMsg, getCompressionConfigFromEndpointConfig(config)); return requestMsg; } @@ -115,7 +117,7 @@ static void handleAcceptEncodingHeader(HttpCarbonMessage outboundRequest, String } static void prepareOutboundRequest(String serviceUri, String path, HttpCarbonMessage outboundRequest, - Boolean nonEntityBodyReq) { + Boolean nonEntityBodyReq, Boolean isHostHeaderSet) { TransactionResourceManager trxResourceManager = TransactionResourceManager.getInstance(); if (trxResourceManager.isInTransaction()) { TransactionLocalContext transactionLocalContext = trxResourceManager.getCurrentTransactionContext(); @@ -132,7 +134,7 @@ static void prepareOutboundRequest(String serviceUri, String path, HttpCarbonMes String host = url.getHost(); setOutboundReqProperties(outboundRequest, url, port, host, nonEntityBodyReq); - setOutboundReqHeaders(outboundRequest, port, host); + setOutboundReqHeaders(outboundRequest, port, host, isHostHeaderSet); } catch (MalformedURLException e) { throw HttpUtil.createHttpError("malformed URL specified. " + e.getMessage(), @@ -158,9 +160,10 @@ private static String encodeWhitespacesInUri(String uri) { return uri.trim().replaceAll(WHITESPACE, "%20"); } - private static void setOutboundReqHeaders(HttpCarbonMessage outboundRequest, int port, String host) { + private static void setOutboundReqHeaders(HttpCarbonMessage outboundRequest, int port, String host, + Boolean isHostHeaderSet) { HttpHeaders headers = outboundRequest.getHeaders(); - setHostHeader(host, port, headers); + setHostHeader(host, port, headers, isHostHeaderSet); setOutboundUserAgent(headers); removeConnectionHeader(headers); } @@ -212,8 +215,8 @@ private static int getStartTime(BObject timestamp) { return 0; } - private static void setHostHeader(String host, int port, HttpHeaders headers) { - if (headers.contains(HttpHeaderNames.HOST)) { + private static void setHostHeader(String host, int port, HttpHeaders headers, Boolean isHostHeaderSet) { + if (isHostHeaderSet && headers.contains(HttpHeaderNames.HOST)) { return; } if (port == 80 || port == 443) { @@ -323,6 +326,10 @@ static boolean isNoEntityBodyRequest(BObject request) { return (Boolean) request.get(HttpConstants.REQUEST_NO_ENTITY_BODY_FIELD); } + static boolean isHostHeaderSet(BObject request) { + return Objects.nonNull(request.getNativeData(SET_HOST_HEADER)); + } + private static boolean dirty(BObject request) { return (Boolean) request.get(HttpConstants.REQUEST_REUSE_STATUS_FIELD); } diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/Execute.java b/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/Execute.java index ba370fb3a3..c047a7d26a 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/Execute.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/client/actions/Execute.java @@ -55,7 +55,8 @@ protected static HttpCarbonMessage createOutboundRequestMsg(BMap