From 94715c2ae9ca8953406ffdd34f0f7d12fb0d4b58 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Thu, 4 Apr 2024 14:37:23 +0530 Subject: [PATCH 1/3] Fix exiting the response pipeline when return nil --- .../stdlib/http/api/HttpResponseInterceptorUnitCallback.java | 3 +-- .../stdlib/http/api/nativeimpl/ExternRequestContext.java | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/HttpResponseInterceptorUnitCallback.java b/native/src/main/java/io/ballerina/stdlib/http/api/HttpResponseInterceptorUnitCallback.java index f9e8d76fff..7c601addb5 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/HttpResponseInterceptorUnitCallback.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/HttpResponseInterceptorUnitCallback.java @@ -114,8 +114,7 @@ private void validateResponseAndProceed(Object result) { return; } - if (result == null) { - requestMessage.setProperty(HttpConstants.RESPONSE_INTERCEPTOR_INDEX, -1); + if (result == null && interceptorId == -1) { sendResponseToNextService(); return; } diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java b/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java index fe0daded1f..bb34ec6149 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/nativeimpl/ExternRequestContext.java @@ -95,6 +95,7 @@ private static Object getNextInterceptor(BObject requestCtx, BArray interceptors "no next service to be returned"); } if (interceptorIndex < 0) { + requestCtx.addNativeData(HttpConstants.RESPONSE_INTERCEPTOR_INDEX, -1); return null; } updateInterceptorIndex(requestCtx, requiredInterceptorType, interceptorIndex); From 8d209d3b1865e68965081e158f65d4a55eeab1f0 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Thu, 4 Apr 2024 15:18:45 +0530 Subject: [PATCH 2/3] Fix test case --- .../tests/interceptors_special_test.bal | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ballerina-tests/http-interceptor-tests/tests/interceptors_special_test.bal b/ballerina-tests/http-interceptor-tests/tests/interceptors_special_test.bal index ddcbcb8c1b..a03849c532 100644 --- a/ballerina-tests/http-interceptor-tests/tests/interceptors_special_test.bal +++ b/ballerina-tests/http-interceptor-tests/tests/interceptors_special_test.bal @@ -259,10 +259,9 @@ service http:InterceptableService / on responseInterceptorWithoutCtxNextServerEP @test:Config{} function testResponseInterceptorWithoutCtxNext() returns error? { http:Response res = check responseInterceptorWithoutCtxNextClientEP->get("/"); - common:assertHeaderValue(check res.getHeader("last-interceptor"), "response-interceptor-without-ctx-next"); - common:assertHeaderValue(check res.getHeader("default-response-interceptor"), "true"); - common:assertHeaderValue(check res.getHeader("response-interceptor-without-ctx-next"), "true"); - common:assertTextPayload(check res.getTextPayload(), "Response from response interceptor"); + common:assertHeaderValue(check res.getHeader("last-interceptor"), "default-response-interceptor"); + common:assertHeaderValue(check res.getHeader("last-response-interceptor"), "true"); + test:assertEquals(res.statusCode, 202); } final http:Client requestInterceptorSkipClientEP = check new("http://localhost:" + requestInterceptorSkipTestPort.toString(), httpVersion = http:HTTP_1_1); From d8e96c0f50073703cb64fd7cb36544074b28faba Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Thu, 4 Apr 2024 15:23:46 +0530 Subject: [PATCH 3/3] Update change log --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index e0ee8206fc..aa9ac1a48c 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - [Address CVE-2024-29025 netty's vulnerability](https://github.com/ballerina-platform/ballerina-library/issues/6242) +- [Fix interceptor pipeline getting exited when there is a `nil` return](https://github.com/ballerina-platform/ballerina-library/issues/6278) ## [2.10.12] - 2024-03-21