use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class OriginResponseReceiver method writeInternal.
private void writeInternal(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!ctx.channel().isActive()) {
ReferenceCountUtil.release(msg);
return;
}
if (msg instanceof HttpRequestMessage) {
promise.addListener((future) -> {
if (!future.isSuccess()) {
Throwable cause = ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).get();
if (cause != null) {
// Set the specific SSL handshake error if the handlers have already caught them
ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).set(null);
fireWriteError("request headers", cause, ctx);
LOG.debug("SSLException is overridden by SSLHandshakeException caught in handler level. Original SSL exception message: ", future.cause());
} else {
fireWriteError("request headers", future.cause(), ctx);
}
}
});
HttpRequestMessage zuulReq = (HttpRequestMessage) msg;
preWriteHook(ctx, zuulReq);
super.write(ctx, buildOriginHttpRequest(zuulReq), promise);
} else if (msg instanceof HttpContent) {
promise.addListener((future) -> {
if (!future.isSuccess()) {
fireWriteError("request content chunk", future.cause(), ctx);
}
});
super.write(ctx, msg, promise);
} else {
// should never happen
ReferenceCountUtil.release(msg);
throw new ZuulException("Received invalid message from client", true);
}
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ZuulEndPointRunner method filter.
@Override
public void filter(final HttpRequestMessage zuulReq) {
if (zuulReq.getContext().isCancelled()) {
PerfMark.event(getClass().getName(), "filterCancelled");
zuulReq.disposeBufferedBody();
logger.debug("Request was cancelled, UUID {}", zuulReq.getContext().getUUID());
return;
}
final String endpointName = getEndPointName(zuulReq.getContext());
try (TaskCloseable ignored = PerfMark.traceTask(this, s -> s.getClass().getSimpleName() + ".filter")) {
Preconditions.checkNotNull(zuulReq, "input message");
addPerfMarkTags(zuulReq);
final ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = getEndpoint(endpointName, zuulReq);
logger.debug("Got endpoint {}, UUID {}", endpoint.filterName(), zuulReq.getContext().getUUID());
setEndpoint(zuulReq, endpoint);
final HttpResponseMessage zuulResp = filter(endpoint, zuulReq);
if ((zuulResp != null) && (!(endpoint instanceof ProxyEndpoint))) {
// EdgeProxyEndpoint calls invokeNextStage internally
logger.debug("Endpoint calling invokeNextStage, UUID {}", zuulReq.getContext().getUUID());
invokeNextStage(zuulResp);
}
} catch (Exception ex) {
handleException(zuulReq, endpointName, ex);
}
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class HttpUtilsTest method getBodySizeIfKnown_returnsResponseBodySize.
@Test
public void getBodySizeIfKnown_returnsResponseBodySize() {
SessionContext context = new SessionContext();
Headers headers = new Headers();
HttpQueryParams queryParams = new HttpQueryParams();
HttpRequestMessage request = new HttpRequestMessageImpl(context, "http", "GET", "/path", queryParams, headers, "127.0.0.1", "scheme", 6666, "server-name");
request.storeInboundRequest();
HttpResponseMessage response = new HttpResponseMessageImpl(context, request, 200);
response.setBodyAsText("Hello world");
assertThat(HttpUtils.getBodySizeIfKnown(response)).isEqualTo(Integer.valueOf(11));
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ClientRequestReceiverTest method multipleHostHeaders_setBadRequestStatus.
@Test
public void multipleHostHeaders_setBadRequestStatus() {
ClientRequestReceiver receiver = new ClientRequestReceiver(null);
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder());
PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry());
// Required for messages
channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
channel.pipeline().addLast(new HttpServerCodec());
channel.pipeline().addLast(receiver);
channel.pipeline().addLast(loggingHandler);
HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/post");
httpRequest.headers().add("Host", "foo.bar.com");
httpRequest.headers().add("Host", "bar.foo.com");
channel.writeOutbound(httpRequest);
ByteBuf byteBuf = channel.readOutbound();
channel.writeInbound(byteBuf);
channel.readInbound();
channel.close();
HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
SessionContext context = request.getContext();
assertEquals(StatusCategoryUtils.getStatusCategory(context), ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST);
assertEquals("Multiple Host headers", context.getError().getMessage());
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ClientRequestReceiverTest method maxHeaderSizeExceeded_setBadRequestStatus.
@Test
public void maxHeaderSizeExceeded_setBadRequestStatus() {
int maxInitialLineLength = BaseZuulChannelInitializer.MAX_INITIAL_LINE_LENGTH.get();
int maxHeaderSize = 10;
int maxChunkSize = BaseZuulChannelInitializer.MAX_CHUNK_SIZE.get();
ClientRequestReceiver receiver = new ClientRequestReceiver(null);
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestEncoder());
PassportLoggingHandler loggingHandler = new PassportLoggingHandler(new DefaultRegistry());
// Required for messages
channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
channel.pipeline().addLast(new HttpServerCodec(maxInitialLineLength, maxHeaderSize, maxChunkSize, false));
channel.pipeline().addLast(receiver);
channel.pipeline().addLast(loggingHandler);
String str = "test-header-value";
ByteBuf buf = Unpooled.buffer(1);
HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/post", buf);
for (int i = 0; i < 100; i++) {
httpRequest.headers().add("test-header" + i, str);
}
channel.writeOutbound(httpRequest);
ByteBuf byteBuf = channel.readOutbound();
channel.writeInbound(byteBuf);
channel.readInbound();
channel.close();
HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
assertEquals(StatusCategoryUtils.getStatusCategory(request.getContext()), ZuulStatusCategory.FAILURE_CLIENT_BAD_REQUEST);
}
Aggregations