Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.function.Predicate;

import javax.ws.rs.core.Response;
import javax.ws.rs.client.ResponseProcessingException;

import org.glassfish.jersey.client.ClientRequest;
import org.glassfish.jersey.client.ClientResponse;
Expand All @@ -38,6 +39,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpObject;
import io.netty.handler.codec.http.HttpResponse;
Expand Down Expand Up @@ -179,33 +181,40 @@ public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
return;
}
if (msg instanceof HttpResponse) {
final HttpResponse response = (HttpResponse) msg;
jerseyResponse = new ClientResponse(new Response.StatusType() {
@Override
public int getStatusCode() {
return response.status().code();
}
if (msg.decoderResult().isFailure()) {
Throwable cause = msg.decoderResult().cause();
ResponseProcessingException ex = new ResponseProcessingException(null, cause);
responseAvailable.completeExceptionally(ex);
return;
} else {
final HttpResponse response = (HttpResponse) msg;
jerseyResponse = new ClientResponse(new Response.StatusType() {
@Override
public int getStatusCode() {
return response.status().code();
}

@Override
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf(response.status().code());
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf(response.status().code());
}

@Override
public String getReasonPhrase() {
return response.status().reasonPhrase();
}
}, jerseyRequest);
@Override
public String getReasonPhrase() {
return response.status().reasonPhrase();
}
}, jerseyRequest);

for (Map.Entry<String, String> entry : response.headers().entries()) {
jerseyResponse.getHeaders().add(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, String> entry : response.headers().entries()) {
jerseyResponse.getHeaders().add(entry.getKey(), entry.getValue());
}

// request entity handling.
nis = new NettyInputStream();
responseDone.whenComplete((_r, th) -> nis.complete(th));
// request entity handling.
nis = new NettyInputStream();
responseDone.whenComplete((_r, th) -> nis.complete(th));

jerseyResponse.setEntityStream(nis);
jerseyResponse.setEntityStream(nis);
}
}
if (msg instanceof HttpContent) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -28,6 +28,7 @@
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;

Expand All @@ -36,6 +37,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;

public class HugeHeaderTest extends JerseyTest {

Expand Down Expand Up @@ -90,13 +92,14 @@ public void testContentHeaderTrunked() {
for (int i = 1; i < 33; i++) {
veryHugeHeader.append(hugeHeader);
}
final Response response = target("test").request()
.header("X-HUGE-HEADER", veryHugeHeader.toString())
.post(null);

assertNull(response.getHeaderString("X-HUGE-HEADER-SIZE"));
assertNull(response.getHeaderString("X-HUGE-HEADER"));
response.close();
try {
target("test").request()
.header("X-HUGE-HEADER", veryHugeHeader.toString())
.post(null);
fail("Expected an exception");
} catch (ProcessingException ex) {
assertEquals("HTTP header is larger than 8192 bytes.", ex.getCause().getCause().getMessage());
}
}

@Test
Expand Down
Loading