diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 4c5a660619..a5fcfaa4cb 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -32,7 +32,7 @@ jobs: - name: Create lib directory if not exists run: mkdir -p ballerina/lib - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@0.23.0 with: scan-type: 'rootfs' scan-ref: '/github/workspace/ballerina/lib' diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 9f37c1a406..19f290fe04 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -29,7 +29,7 @@ jobs: - name: Create lib directory if not exists run: mkdir -p ballerina/lib - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@0.23.0 with: scan-type: 'rootfs' scan-ref: '/github/workspace/ballerina/lib' diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 3e3b3389d3..7258d43e39 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -24,7 +24,7 @@ jobs: - name: Create lib directory if not exists run: mkdir -p ballerina/lib - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@0.23.0 with: scan-type: 'rootfs' scan-ref: '/github/workspace/ballerina/lib' diff --git a/.trivyignore b/.trivyignore index 2738392882..eadd990ef6 100644 --- a/.trivyignore +++ b/.trivyignore @@ -2,3 +2,4 @@ CVE-2024-34447 CVE-2024-29857 CVE-2024-30171 CVE-2024-30172 +CVE-2024-7254 diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index b00df5fe42..909301ab74 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -255,7 +255,7 @@ task startLdapServer() { if (!stdOut.toString().contains("openldap-server")) { println "Starting LDAP server." exec { - commandLine 'sh', '-c', "docker-compose -f $project.projectDir/resources/openldap/docker-compose.yml up -d" + commandLine 'sh', '-c', "docker compose -f $project.projectDir/resources/openldap/compose.yml up -d" standardOutput = stdOut } println stdOut.toString() diff --git a/ballerina-tests/http-advanced-tests/Ballerina.toml b/ballerina-tests/http-advanced-tests/Ballerina.toml index cba90cbcec..404dcde23a 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-advanced-tests/Dependencies.toml b/ballerina-tests/http-advanced-tests/Dependencies.toml index e3e35581c2..15fdce6b91 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -105,7 +105,7 @@ modules = [ [[package]] org = "ballerina" name = "http_advanced_tests" -version = "2.9.9" +version = "2.9.10" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "file"}, @@ -125,7 +125,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" 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 4fe183b59b..df9965d2f6 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-client-tests/Dependencies.toml b/ballerina-tests/http-client-tests/Dependencies.toml index c6c8f86ae3..77e72ae1ff 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_client_tests" -version = "2.9.9" +version = "2.9.10" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http-dispatching-tests/Ballerina.toml b/ballerina-tests/http-dispatching-tests/Ballerina.toml index 0bff69bbf9..182472df5a 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-dispatching-tests/Dependencies.toml b/ballerina-tests/http-dispatching-tests/Dependencies.toml index 9c8a1755fb..1e08f4e225 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_dispatching_tests" -version = "2.9.9" +version = "2.9.10" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -124,7 +124,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" 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 6468b2046b..ada277b25f 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-interceptor-tests/Dependencies.toml b/ballerina-tests/http-interceptor-tests/Dependencies.toml index 91accd1445..eb9a736456 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_interceptor_tests" -version = "2.9.9" +version = "2.9.10" 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.9.9" +version = "2.9.10" 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 3934b4d4fe..c479211b1d 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-misc-tests/Dependencies.toml b/ballerina-tests/http-misc-tests/Dependencies.toml index 9632523345..452a73694d 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_misc_tests" -version = "2.9.9" +version = "2.9.10" 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, 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 308cd7b93a..31c5e1c1a1 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,3 +277,24 @@ 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]); +} + diff --git a/ballerina-tests/http-resiliency-tests/Ballerina.toml b/ballerina-tests/http-resiliency-tests/Ballerina.toml index e0fff682d9..183de26eee 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-resiliency-tests/Dependencies.toml b/ballerina-tests/http-resiliency-tests/Dependencies.toml index c0a49abbb9..cff5bb79a6 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_resiliency_tests" -version = "2.9.9" +version = "2.9.10" 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.9.9" +version = "2.9.10" 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 76b2571f16..cb6b69d3b9 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-security-tests/Dependencies.toml b/ballerina-tests/http-security-tests/Dependencies.toml index 5c00f8fe4f..561ec2c956 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_security_tests" -version = "2.9.9" +version = "2.9.10" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "http"}, @@ -120,7 +120,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" 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 fa15dda5ce..40225f4220 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http-service-tests/Dependencies.toml b/ballerina-tests/http-service-tests/Dependencies.toml index 4775296da8..d88f59373c 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_service_tests" -version = "2.9.9" +version = "2.9.10" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" 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 bd46ac205f..b520ab9384 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.9.9" +version = "2.9.10" diff --git a/ballerina-tests/http-test-common/Dependencies.toml b/ballerina-tests/http-test-common/Dependencies.toml index 03db79b51b..58dbad57d7 100644 --- a/ballerina-tests/http-test-common/Dependencies.toml +++ b/ballerina-tests/http-test-common/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.7.0" [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" 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 76764c6d9a..7ad9defee9 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.9.9" +version = "2.9.10" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.9.9" +version = "2.9.10" [platform.java11] graalvmCompatible = true [[platform.java11.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.9.9.jar" +path = "../../test-utils/build/libs/http-test-utils-2.9.10-SNAPSHOT.jar" diff --git a/ballerina-tests/http2-tests/Dependencies.toml b/ballerina-tests/http2-tests/Dependencies.toml index ae329272ab..a25c54c065 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.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http2_tests" -version = "2.9.9" +version = "2.9.10" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.9.9" +version = "2.9.10" scope = "testOnly" dependencies = [ {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/resources/openldap/docker-compose.yml b/ballerina-tests/resources/openldap/compose.yml similarity index 97% rename from ballerina-tests/resources/openldap/docker-compose.yml rename to ballerina-tests/resources/openldap/compose.yml index 63d25ce840..23599088b2 100644 --- a/ballerina-tests/resources/openldap/docker-compose.yml +++ b/ballerina-tests/resources/openldap/compose.yml @@ -1,4 +1,3 @@ -version: '3.7' services: ldap_server: image: osixia/openldap:1.3.0 diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 09fac0d568..81de6e9459 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "http" -version = "2.9.9" +version = "2.9.10" authors = ["Ballerina"] keywords = ["http", "network", "service", "listener", "client"] repository = "https://github.com/ballerina-platform/module-ballerina-http" @@ -16,8 +16,8 @@ graalvmCompatible = true [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" artifactId = "http-native" -version = "2.9.9" -path = "../native/build/libs/http-native-2.9.9.jar" +version = "2.9.10" +path = "../native/build/libs/http-native-2.9.10-SNAPSHOT.jar" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 46ab03f8c8..4d458245a7 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.9.9.jar" +path = "../compiler-plugin/build/libs/http-compiler-plugin-2.9.10-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index f11bb93523..595987658c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -76,7 +76,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.9.9" +version = "2.9.10" 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 38ad126bf2..b4725cecd2 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 307f3d9a82..348bcee566 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 f9436c5586..f125c69960 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] + +### Fixed + +- [Fix duplicating `Content-Type` header via the `addHeader` method](https://github.com/ballerina-platform/ballerina-library/issues/7268) + ## [2.9.9] - 2024-05-29 ### Fixed