Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle client level header size validation response before sending to server #1849

Merged
merged 9 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ jobs:
call_workflow:
name: Run PR Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@main
uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@dilanSachi-patch-1
dilanSachi marked this conversation as resolved.
Show resolved Hide resolved
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,33 @@ function testHttp2ValidHeaderLength() returns error? {
}

//Tests the behaviour when header size is greater than the configured threshold
// TODO: Enable after fixing this issue : https://github.com/ballerina-platform/ballerina-standard-library/issues/3963
@test:Config {
enable: false
}
@test:Config {}
function testHttp2InvalidHeaderLength() returns error? {
http:Client limitClient = check new ("http://localhost:" + http2RequestLimitsTestPort3.toString(),
http2Settings = {http2PriorKnowledge: true});
http:Response response = check limitClient->get("/lowRequestHeaderLimit/invalidHeaderSize", {"X-Test": getLargeHeader()});
http:Response|http:Error response = limitClient->get("/lowRequestHeaderLimit/invalidHeaderSize", {"X-Test": getLargeHeader()});
//431 Request Header Fields Too Large
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
if response is http:Error {
test:assertTrue(response is http:ClientError);
test:assertEquals(response.message(), "Header size exceeded max allowed size (600)");
} else {
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
}
}

// Tests the fallback behaviour when header size is greater than the configured http2 service
// TODO: Enable after fixing this issue : https://github.com/ballerina-platform/ballerina-standard-library/issues/3963
@test:Config {
enable: false
}
@test:Config {}
function testHttp2Http2ServiceInvalidHeaderLength() returns error? {
http:Client limitClient = check new ("http://localhost:" + requestLimitsTestPort5.toString(),
http2Settings = {http2PriorKnowledge: true});
http:Response response = check limitClient->get("/http2service/invalidHeaderSize", {"X-Test": getLargeHeader()});
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
http:Response|http:Error response = limitClient->get("/http2service/invalidHeaderSize", {"X-Test": getLargeHeader()});
if response is http:Error {
test:assertTrue(response is http:ClientError);
test:assertEquals(response.message(), "Header size exceeded max allowed size (850)");
} else {
test:assertEquals(response.statusCode, 431, msg = "Found unexpected output");
}
}

//Tests the behaviour when payload size is greater than the configured threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.DefaultLastHttpContent;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
Expand Down Expand Up @@ -320,9 +321,13 @@ public static void writeHttp2Headers(ChannelHandlerContext ctx, OutboundMsgHolde
return;
}
}

encoder.writeHeaders(ctx, streamId, http2Headers, dependencyId, weight, false, 0, endStream,
ctx.newPromise());
ChannelPromise promise = ctx.newPromise();
encoder.writeHeaders(ctx, streamId, http2Headers, dependencyId, weight, false, 0, endStream, promise);
promise.addListener((ChannelFutureListener) channelFuture -> {
if (!channelFuture.isSuccess()) {
outboundMsgHolder.getResponseFuture().notifyHttpListener(channelFuture.cause());
}
});
encoder.flowController().writePendingBytes();
ctx.flush();

Expand Down
Loading