diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index db61bedcd8..cc578dcab6 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -29,6 +29,7 @@ on: - 2201.7.x - 2201.8.x - 2201.9.x + - java21 types: [opened, synchronize, reopened, labeled, unlabeled] concurrency: diff --git a/ballerina-tests/http-advanced-tests/Ballerina.toml b/ballerina-tests/http-advanced-tests/Ballerina.toml index 0c540ca7cd..5bd81f79fe 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-advanced-tests/Dependencies.toml b/ballerina-tests/http-advanced-tests/Dependencies.toml index c2fcae84df..25e901668f 100644 --- a/ballerina-tests/http-advanced-tests/Dependencies.toml +++ b/ballerina-tests/http-advanced-tests/Dependencies.toml @@ -71,7 +71,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -104,7 +104,7 @@ modules = [ [[package]] org = "ballerina" name = "http_advanced_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "file"}, @@ -124,7 +124,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-client-tests/Ballerina.toml b/ballerina-tests/http-client-tests/Ballerina.toml index 358b168e05..dedf342130 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-client-tests/Dependencies.toml b/ballerina-tests/http-client-tests/Dependencies.toml index cd6660bbe0..7a6070d524 100644 --- a/ballerina-tests/http-client-tests/Dependencies.toml +++ b/ballerina-tests/http-client-tests/Dependencies.toml @@ -68,7 +68,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -101,7 +101,7 @@ modules = [ [[package]] org = "ballerina" name = "http_client_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -120,7 +120,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-dispatching-tests/Ballerina.toml b/ballerina-tests/http-dispatching-tests/Ballerina.toml index 20d1c2d98b..ba732b5a5d 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-dispatching-tests/Dependencies.toml b/ballerina-tests/http-dispatching-tests/Dependencies.toml index 6a10c69405..8fc36dfae1 100644 --- a/ballerina-tests/http-dispatching-tests/Dependencies.toml +++ b/ballerina-tests/http-dispatching-tests/Dependencies.toml @@ -68,7 +68,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -101,7 +101,7 @@ modules = [ [[package]] org = "ballerina" name = "http_dispatching_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -123,7 +123,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-interceptor-tests/Ballerina.toml b/ballerina-tests/http-interceptor-tests/Ballerina.toml index 2c26dac811..b1719db543 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-interceptor-tests/Dependencies.toml b/ballerina-tests/http-interceptor-tests/Dependencies.toml index 892eb64feb..308b7090d0 100644 --- a/ballerina-tests/http-interceptor-tests/Dependencies.toml +++ b/ballerina-tests/http-interceptor-tests/Dependencies.toml @@ -65,7 +65,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -98,7 +98,7 @@ modules = [ [[package]] org = "ballerina" name = "http_interceptor_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -114,7 +114,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-misc-tests/Ballerina.toml b/ballerina-tests/http-misc-tests/Ballerina.toml index e6f4275ae1..aae3bb55d2 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-misc-tests/Dependencies.toml b/ballerina-tests/http-misc-tests/Dependencies.toml index 39939e32c3..9aaec69b4a 100644 --- a/ballerina-tests/http-misc-tests/Dependencies.toml +++ b/ballerina-tests/http-misc-tests/Dependencies.toml @@ -65,7 +65,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -98,7 +98,7 @@ modules = [ [[package]] org = "ballerina" name = "http_misc_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -117,7 +117,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-misc-tests/tests/http_header_test.bal b/ballerina-tests/http-misc-tests/tests/http_header_test.bal index 72a0171459..45d7256fb8 100644 --- a/ballerina-tests/http-misc-tests/tests/http_header_test.bal +++ b/ballerina-tests/http-misc-tests/tests/http_header_test.bal @@ -14,6 +14,7 @@ // specific language governing permissions and limitations // under the License. +import ballerina/mime; import ballerina/test; import ballerina/http; import ballerina/http_test_common as common; @@ -276,6 +277,27 @@ function testPassthruWithBody() returns error? { } } +@test:Config {} +function testAddHeaderWithContentType() returns error? { + http:Request req = new; + check req.setContentType(mime:APPLICATION_JSON); + test:assertEquals(check req.getHeaders(http:CONTENT_TYPE), [mime:APPLICATION_JSON]); + req.addHeader(http:CONTENT_TYPE, mime:APPLICATION_XML); + test:assertEquals(check req.getHeaders(http:CONTENT_TYPE), [mime:APPLICATION_XML]); + + http:Response res = new; + check res.setContentType(mime:APPLICATION_JSON); + test:assertEquals(check res.getHeaders(http:CONTENT_TYPE), [mime:APPLICATION_JSON]); + res.addHeader(http:CONTENT_TYPE, mime:APPLICATION_XML); + test:assertEquals(check res.getHeaders(http:CONTENT_TYPE), [mime:APPLICATION_XML]); + + http:PushPromise pushPromise = new; + pushPromise.addHeader(http:CONTENT_TYPE, mime:APPLICATION_JSON); + test:assertEquals(pushPromise.getHeaders(http:CONTENT_TYPE), [mime:APPLICATION_JSON]); + pushPromise.addHeader(http:CONTENT_TYPE, mime:APPLICATION_XML); + test:assertEquals(pushPromise.getHeaders(http:CONTENT_TYPE), [mime:APPLICATION_XML]); +} + type Headers record {| @http:Header {name: "X-API-VERSION"} string apiVersion; diff --git a/ballerina-tests/http-resiliency-tests/Ballerina.toml b/ballerina-tests/http-resiliency-tests/Ballerina.toml index 15d751433a..f3bdbe63c8 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-resiliency-tests/Dependencies.toml b/ballerina-tests/http-resiliency-tests/Dependencies.toml index 258bcbfc39..d8ec966c51 100644 --- a/ballerina-tests/http-resiliency-tests/Dependencies.toml +++ b/ballerina-tests/http-resiliency-tests/Dependencies.toml @@ -65,7 +65,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -98,7 +98,7 @@ modules = [ [[package]] org = "ballerina" name = "http_resiliency_tests" -version = "2.12.1" +version = "2.13.0" 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.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-security-tests/Ballerina.toml b/ballerina-tests/http-security-tests/Ballerina.toml index d1882132c8..544874fabe 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-security-tests/Dependencies.toml b/ballerina-tests/http-security-tests/Dependencies.toml index 76ecc3fdba..3de9d0e5b7 100644 --- a/ballerina-tests/http-security-tests/Dependencies.toml +++ b/ballerina-tests/http-security-tests/Dependencies.toml @@ -68,7 +68,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -101,7 +101,7 @@ modules = [ [[package]] org = "ballerina" name = "http_security_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "http"}, @@ -119,7 +119,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-service-tests/Ballerina.toml b/ballerina-tests/http-service-tests/Ballerina.toml index ce1f463d94..ce0ff69ea0 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http-service-tests/Dependencies.toml b/ballerina-tests/http-service-tests/Dependencies.toml index da07ac01b5..3db663d608 100644 --- a/ballerina-tests/http-service-tests/Dependencies.toml +++ b/ballerina-tests/http-service-tests/Dependencies.toml @@ -68,7 +68,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -101,7 +101,7 @@ modules = [ [[package]] org = "ballerina" name = "http_service_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -120,7 +120,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-test-common/Ballerina.toml b/ballerina-tests/http-test-common/Ballerina.toml index a58967ad4e..0c2db5776f 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.12.1" +version = "2.13.0" diff --git a/ballerina-tests/http-test-common/Dependencies.toml b/ballerina-tests/http-test-common/Dependencies.toml index cc11913884..3679a7f0af 100644 --- a/ballerina-tests/http-test-common/Dependencies.toml +++ b/ballerina-tests/http-test-common/Dependencies.toml @@ -60,7 +60,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -92,7 +92,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http2-tests/Ballerina.toml b/ballerina-tests/http2-tests/Ballerina.toml index 78dd5cdcb0..01b332296b 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.12.1" +version = "2.13.0" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.1" +version = "2.13.0" [platform.java21] graalvmCompatible = true [[platform.java21.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" +path = "../../test-utils/build/libs/http-test-utils-2.13.0-SNAPSHOT.jar" diff --git a/ballerina-tests/http2-tests/Dependencies.toml b/ballerina-tests/http2-tests/Dependencies.toml index 08adbd7311..02fd566c5a 100644 --- a/ballerina-tests/http2-tests/Dependencies.toml +++ b/ballerina-tests/http2-tests/Dependencies.toml @@ -68,7 +68,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -101,7 +101,7 @@ modules = [ [[package]] org = "ballerina" name = "http2_tests" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -120,7 +120,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.1" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index b0c31c6cde..4ae4986ba8 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" authors = ["Ballerina"] keywords = ["http", "network", "service", "listener", "client"] repository = "https://github.com/ballerina-platform/module-ballerina-http" @@ -16,8 +16,8 @@ graalvmCompatible = true [[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "http-native" -version = "2.12.1" -path = "../native/build/libs/http-native-2.12.1-SNAPSHOT.jar" +version = "2.13.0" +path = "../native/build/libs/http-native-2.13.0-SNAPSHOT.jar" [[platform.java21.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 751236dbb9..a5094ce6de 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "http-compiler-plugin" class = "io.ballerina.stdlib.http.compiler.HttpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/http-compiler-plugin-2.12.1-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/http-compiler-plugin-2.13.0-SNAPSHOT.jar" [[dependency]] path = "../compiler-plugin/build/libs/ballerina-to-openapi-2.1.0.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 9b8446885c..10711cd473 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -75,7 +75,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.1" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, diff --git a/ballerina/http2_push_promise.bal b/ballerina/http2_push_promise.bal index 1c0540faf4..795d441b03 100644 --- a/ballerina/http2_push_promise.bal +++ b/ballerina/http2_push_promise.bal @@ -59,11 +59,15 @@ public class PushPromise { return externPromiseGetHeaders(self, headerName); } - # Adds the specified key/value pair as an HTTP header to the `http:PushPromise`. + # Adds the specified key/value pair as an HTTP header to the `http:PushPromise`. In the case of the `Content-Type` + # header, the existing value is replaced with the specified value. # # + headerName - The header name # + headerValue - The header value public isolated function addHeader(string headerName, string headerValue) { + if headerName.equalsIgnoreCaseAscii(CONTENT_TYPE) { + return externPromiseSetHeader(self, headerName, headerValue); + } return externPromiseAddHeader(self, headerName, headerValue); } diff --git a/ballerina/http_request.bal b/ballerina/http_request.bal index 9a1f35051a..3d5de29bab 100644 --- a/ballerina/http_request.bal +++ b/ballerina/http_request.bal @@ -164,12 +164,17 @@ public class Request { externRequestSetHeader(self, headerName, headerValue); } - # Adds the specified header to the request. Existing header values are not replaced. Panic if an illegal header is passed. + # Adds the specified header to the request. Existing header values are not replaced, except for the `Content-Type` + # header. In the case of the `Content-Type` header, the existing value is replaced with the specified value. + # Panic if an illegal header is passed. # # + headerName - The header name # + headerValue - The header value public isolated function addHeader(string headerName, string headerValue) { - externRequestAddHeader(self, headerName, headerValue); + if headerName.equalsIgnoreCaseAscii(CONTENT_TYPE) { + return externRequestSetHeader(self, headerName, headerValue); + } + return externRequestAddHeader(self, headerName, headerValue); } # Removes the specified header from the request. diff --git a/ballerina/http_response.bal b/ballerina/http_response.bal index e1f9c08ad1..002621e8f3 100644 --- a/ballerina/http_response.bal +++ b/ballerina/http_response.bal @@ -109,13 +109,18 @@ public class Response { return externResponseGetHeader(self, headerName, position); } - # Adds the specified header to the response. Existing header values are not replaced. Panic if an illegal header is passed. + # Adds the specified header to the response. Existing header values are not replaced, except for the `Content-Type` + # header. In the case of the `Content-Type` header, the existing value is replaced with the specified value. + #. Panic if an illegal header is passed. # # + headerName - The header name # + headerValue - The header value # + position - Represents the position of the header as an optional parameter. If the position is `http:TRAILING`, # the entity-body of the `Response` must be accessed initially. public isolated function addHeader(string headerName, string headerValue, HeaderPosition position = LEADING) { + if headerName.equalsIgnoreCaseAscii(CONTENT_TYPE) { + return externResponseSetHeader(self, headerName, headerValue, position); + } return externResponseAddHeader(self, headerName, headerValue, position); } diff --git a/changelog.md b/changelog.md index f427f1fed7..4935b7c73b 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - [Address CVE-2024-7254 vulnerability](https://github.com/ballerina-platform/ballerina-library/issues/7013) +- [Fix duplicating `Content-Type` header via the `addHeader` method](https://github.com/ballerina-platform/ballerina-library/issues/7268) ## [2.12.0] - 2024-08-20 diff --git a/gradle.properties b/gradle.properties index d4b478cb91..9f8c6377eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.caching=true group=io.ballerina.stdlib -version=2.12.1-SNAPSHOT +version=2.13.0-SNAPSHOT ballerinaLangVersion=2201.10.0-20241011-161100-51978649 ballerinaTomlParserVersion=1.2.2 commonsLang3Version=3.12.0 diff --git a/load-tests/accesslog_enabled/results/summary.csv b/load-tests/accesslog_enabled/results/summary.csv index 67f1a2d387..fd4df0d5d6 100644 --- a/load-tests/accesslog_enabled/results/summary.csv +++ b/load-tests/accesslog_enabled/results/summary.csv @@ -52,3 +52,6 @@ HTTP Request,9272622,20,16,42,55,85,0,535,0.00%,2664.6,640.1,17.53,1728584041,50 HTTP Request,9380412,20,16,41,54,84,0,641,0.00%,2695.6,647.6,17.33,1728670466,50,60 HTTP Request,9032405,21,17,43,56,86,0,669,0.00%,2595.6,623.5,17.89,1728756783,50,60 HTTP Request,8805084,21,17,44,58,89,0,532,0.00%,2530.3,607.8,18.43,1728929611,50,60 +HTTP Request,9066483,21,17,43,56,87,0,649,0.00%,2605.4,625.9,17.84,1729016017,50,60 +HTTP Request,8984950,21,17,43,57,87,0,631,0.00%,2581.9,620.3,18.05,1729102416,50,60 +HTTP Request,9050137,21,17,43,56,87,0,585,0.00%,2600.6,624.8,17.76,1729188824,50,60 diff --git a/load-tests/h1_h1_passthrough/results/summary.csv b/load-tests/h1_h1_passthrough/results/summary.csv index f068bb7148..6dbbf02ac3 100644 --- a/load-tests/h1_h1_passthrough/results/summary.csv +++ b/load-tests/h1_h1_passthrough/results/summary.csv @@ -586,3 +586,6 @@ HTTP Request,11445236,16,12,34,47,82,0,690,0.00%,3288.9,790.1,16.15,1728587905,5 HTTP Request,11317446,16,12,35,47,82,0,614,0.00%,3252.2,781.3,16.12,1728674361,50,60 HTTP Request,11085446,16,12,35,48,84,0,554,0.00%,3185.5,765.3,16.49,1728760680,50,60 HTTP Request,10834246,17,12,36,49,85,0,702,0.00%,3113.3,747.9,16.87,1728933488,50,60 +HTTP Request,11107994,17,12,36,48,84,0,570,0.00%,3192.0,766.8,16.42,1729019918,50,60 +HTTP Request,10868819,17,12,36,49,85,0,649,0.00%,3123.3,750.3,16.77,1729106333,50,60 +HTTP Request,10949926,17,12,36,49,84,0,692,0.00%,3146.6,755.9,16.52,1729192715,50,60 diff --git a/load-tests/h1_transformation/results/summary.csv b/load-tests/h1_transformation/results/summary.csv index 74edf05cbb..c3d995611e 100644 --- a/load-tests/h1_transformation/results/summary.csv +++ b/load-tests/h1_transformation/results/summary.csv @@ -592,3 +592,6 @@ HTTP Request,9413063,21,20,37,42,57,1,420,0.00%,2705.0,739.6,11.60,1728591846,50 HTTP Request,9530734,21,19,37,42,56,1,359,0.00%,2738.8,748.9,11.53,1728678279,50,60 HTTP Request,9081349,22,20,38,44,59,1,362,0.00%,2609.6,713.6,12.09,1728764640,50,60 HTTP Request,8800966,23,21,40,45,61,1,366,0.00%,2529.1,691.5,12.39,1728937423,50,60 +HTTP Request,8883008,22,21,39,45,60,1,324,0.00%,2552.6,698.0,12.15,1729023823,50,60 +HTTP Request,8736152,23,21,40,46,61,1,312,0.00%,2510.4,686.4,12.34,1729110310,50,60 +HTTP Request,8916171,22,21,39,45,59,1,273,0.00%,2562.2,700.6,12.04,1729196733,50,60 diff --git a/load-tests/h1c_h1c_passthrough/results/summary.csv b/load-tests/h1c_h1c_passthrough/results/summary.csv index d7788054b9..5b31db0ad5 100644 --- a/load-tests/h1c_h1c_passthrough/results/summary.csv +++ b/load-tests/h1c_h1c_passthrough/results/summary.csv @@ -592,3 +592,6 @@ HTTP Request,13067177,14,12,29,35,55,0,281,0.00%,3755.0,667.4,11.12,1728595725,5 HTTP Request,13437045,14,12,28,34,53,0,350,0.00%,3861.3,686.3,10.79,1728682193,50,60 HTTP Request,12758737,15,12,30,36,56,0,294,0.00%,3666.4,651.6,11.41,1728768549,50,60 HTTP Request,12534798,15,12,30,37,57,0,323,0.00%,3602.0,640.2,11.61,1728941304,50,60 +HTTP Request,12790104,15,12,30,36,56,0,328,0.00%,3675.4,653.2,11.33,1729027735,50,60 +HTTP Request,12978005,14,12,29,36,56,0,254,0.00%,3729.4,662.8,11.32,1729114220,50,60 +HTTP Request,12740832,15,12,30,36,55,0,308,0.00%,3661.2,650.7,11.27,1729200655,50,60 diff --git a/load-tests/h1c_transformation/results/summary.csv b/load-tests/h1c_transformation/results/summary.csv index d339b81107..bd87f33e53 100644 --- a/load-tests/h1c_transformation/results/summary.csv +++ b/load-tests/h1c_transformation/results/summary.csv @@ -587,3 +587,6 @@ HTTP Request,9266317,22,19,34,46,70,1,246,0.00%,2662.8,561.7,12.05,1728599627,50 HTTP Request,9590594,21,19,33,46,67,1,192,0.00%,2756.0,581.3,11.66,1728686097,50,60 HTTP Request,9357574,21,19,34,42,67,1,184,0.00%,2689.0,567.2,11.48,1728772418,50,60 HTTP Request,9012796,22,20,35,47,69,1,237,0.00%,2589.9,546.3,12.09,1728945172,50,60 +HTTP Request,8972214,22,20,35,49,71,1,309,0.00%,2578.3,543.8,12.43,1729031607,50,60 +HTTP Request,9360625,21,19,34,48,67,1,166,0.00%,2689.9,567.4,11.90,1729118103,50,60 +HTTP Request,8868640,23,20,36,48,72,1,191,0.00%,2548.5,537.6,12.38,1729204546,50,60 diff --git a/load-tests/h2_h1c_passthrough/results/summary.csv b/load-tests/h2_h1c_passthrough/results/summary.csv index 12d15ca47d..9f1afe6683 100644 --- a/load-tests/h2_h1c_passthrough/results/summary.csv +++ b/load-tests/h2_h1c_passthrough/results/summary.csv @@ -542,3 +542,6 @@ H2-H1C Passthrough,5865,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1728600474,0,1 H2-H1C Passthrough,5873,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1728686927,0,1 H2-H1C Passthrough,5873,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1728773263,0,1 H2-H1C Passthrough,5859,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1728946035,0,1 +H2-H1C Passthrough,5857,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1729032456,0,1 +H2-H1C Passthrough,5868,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1729118951,0,1 +H2-H1C Passthrough,5857,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1729205414,0,1 diff --git a/load-tests/interceptors_passthrough/results/summary.csv b/load-tests/interceptors_passthrough/results/summary.csv index 44e0ea9fa4..17a6faf054 100644 --- a/load-tests/interceptors_passthrough/results/summary.csv +++ b/load-tests/interceptors_passthrough/results/summary.csv @@ -294,3 +294,6 @@ Test Request,220908,948,30,124,259,30027,1,50616,4.37%,63.1,9.7,4892.10,17286043 Test Request,217163,964,29,123,254,29713,1,52765,4.06%,62.1,8.1,4904.73,1728690798,50,60 Test Request,230764,907,30,139,620,30025,1,51444,5.26%,65.8,9.8,4385.02,1728777158,50,60 Test Request,227856,919,31,132,263,30027,1,58683,4.17%,65.0,10.0,4838.28,1728949917,50,60 +Test Request,220602,949,31,124,215,29186,1,30036,3.66%,63.1,7.5,4889.81,1729036341,50,60 +Test Request,223390,938,29,121,224,30023,1,47321,3.66%,63.7,9.2,4840.76,1729122800,50,60 +Test Request,228996,914,30,126,233,29429,1,30034,3.80%,65.5,8.2,4768.81,1729209280,50,60 diff --git a/load-tests/observability_enabled/results/summary.csv b/load-tests/observability_enabled/results/summary.csv index 23f348f5ff..3255ff1d7d 100644 --- a/load-tests/observability_enabled/results/summary.csv +++ b/load-tests/observability_enabled/results/summary.csv @@ -574,3 +574,6 @@ HTTP Request,17154363,11,4,25,45,115,0,976,0.00%,4929.5,736.5,23.76,1728608204,5 HTTP Request,17294964,11,4,25,44,114,0,1001,0.00%,4969.9,742.5,23.60,1728694779,50,60 HTTP Request,16048329,12,5,27,48,119,0,1115,0.00%,4611.7,689.0,24.85,1728781075,50,60 HTTP Request,16303331,12,5,27,45,111,0,1151,0.00%,4684.9,700.0,22.91,1728953803,50,60 +HTTP Request,16457558,12,5,27,47,118,0,1083,0.00%,4729.2,706.6,24.51,1729040228,50,60 +HTTP Request,16430216,12,5,27,46,116,0,1002,0.00%,4721.4,705.4,23.93,1729126697,50,60 +HTTP Request,16357905,12,5,27,46,113,0,1158,0.00%,4700.6,702.3,23.52,1729213179,50,60 diff --git a/load-tests/snowpeak_passthrough/results/summary.csv b/load-tests/snowpeak_passthrough/results/summary.csv index 6de040771b..686fb7d5cc 100644 --- a/load-tests/snowpeak_passthrough/results/summary.csv +++ b/load-tests/snowpeak_passthrough/results/summary.csv @@ -426,3 +426,6 @@ Retrieve Available Locations,7290196,28,16,65,70,84,0,507,0.00%,2094.8,202.5,23. Retrieve Available Locations,7523398,27,15,65,69,80,0,415,0.00%,2161.9,209.0,23.20,1728698688,50,60 Retrieve Available Locations,7281507,28,16,65,70,82,0,514,0.00%,2092.4,202.3,23.29,1728784956,50,60 Retrieve Available Locations,7264596,28,17,65,69,80,0,193,0.00%,2087.6,201.8,22.87,1728957735,50,60 +Retrieve Available Locations,6952009,29,17,67,71,84,0,504,0.00%,1997.7,193.1,24.02,1729044125,50,60 +Retrieve Available Locations,7231847,28,16,66,70,83,0,391,0.00%,2078.1,200.9,23.46,1729130548,50,60 +Retrieve Available Locations,6702677,30,18,68,73,86,0,677,0.00%,1926.1,186.2,24.39,1729217054,50,60