use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ProxyEndpoint method transformRequest.
/* static utility methods */
protected HttpRequestMessage transformRequest(HttpRequestMessage requestMsg) {
final HttpRequestMessage massagedRequest = massageRequestURI(requestMsg);
Headers headers = massagedRequest.getHeaders();
REQUEST_HEADERS_TO_REMOVE.forEach(headerName -> headers.remove(headerName.getName()));
addCustomRequestHeaders(headers);
// Add X-Forwarded headers if not already there.
ProxyUtils.addXForwardedHeaders(massagedRequest);
return massagedRequest;
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ClientRequestReceiverTest method setStatusCategoryForHttpPipelining.
@Test
public void setStatusCategoryForHttpPipelining() {
EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null));
channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "?ELhAWDLM1hwm8bhU0UT4", Unpooled.buffer());
// Write the message and save a copy
channel.writeInbound(request);
final HttpRequestMessage inboundRequest = ClientRequestReceiver.getRequestFromChannel(channel);
// Set the attr to emulate pipelining rejection
channel.attr(HttpLifecycleChannelHandler.ATTR_HTTP_PIPELINE_REJECT).set(Boolean.TRUE);
// Fire completion event
channel.pipeline().fireUserEventTriggered(new CompleteEvent(CompleteReason.PIPELINE_REJECT, request, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)));
channel.close();
assertEquals(ZuulStatusCategory.FAILURE_CLIENT_PIPELINE_REJECT, StatusCategoryUtils.getStatusCategory(inboundRequest.getContext()));
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class BaseZuulFilterRunner method handleException.
protected void handleException(final ZuulMessage zuulMesg, final String filterName, final Exception ex) {
HttpRequestInfo zuulReq = null;
if (zuulMesg instanceof HttpRequestMessage) {
zuulReq = (HttpRequestMessage) zuulMesg;
} else if (zuulMesg instanceof HttpResponseMessage) {
zuulReq = ((HttpResponseMessage) zuulMesg).getInboundRequest();
}
final String path = (zuulReq != null) ? zuulReq.getPathAndQuery() : "-";
final String method = (zuulReq != null) ? zuulReq.getMethod() : "-";
final String errMesg = "Error with filter: " + filterName + ", path: " + path + ", method: " + method;
logger.error(errMesg, ex);
getChannelHandlerContext(zuulMesg).fireExceptionCaught(ex);
}
use of com.netflix.zuul.message.http.HttpRequestMessage in project zuul by Netflix.
the class ZuulEndPointRunner method getEndpoint.
protected ZuulFilter<HttpRequestMessage, HttpResponseMessage> getEndpoint(final String endpointName, final HttpRequestMessage zuulRequest) {
final SessionContext zuulCtx = zuulRequest.getContext();
if (zuulCtx.getStaticResponse() != null) {
return STATIC_RESPONSE_ENDPOINT;
}
if (endpointName == null) {
return new MissingEndpointHandlingFilter("NO_ENDPOINT_NAME");
}
if (PROXY_ENDPOINT_FILTER_NAME.equals(endpointName)) {
return newProxyEndpoint(zuulRequest);
}
final Endpoint<HttpRequestMessage, HttpResponseMessage> filter = getEndpointFilter(endpointName);
if (filter == null) {
return new MissingEndpointHandlingFilter(endpointName);
}
return filter;
}
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, final HttpContent chunk) {
if (zuulReq.getContext().isCancelled()) {
chunk.release();
return;
}
String endpointName = "-";
try (TaskCloseable ignored = PerfMark.traceTask(this, s -> s.getClass().getSimpleName() + ".filterChunk")) {
addPerfMarkTags(zuulReq);
ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = Preconditions.checkNotNull(getEndpoint(zuulReq), "endpoint");
endpointName = endpoint.filterName();
final HttpContent newChunk = endpoint.processContentChunk(zuulReq, chunk);
if (newChunk != null) {
// Endpoints do not directly forward content chunks to next stage in the filter chain.
zuulReq.bufferBodyContents(newChunk);
// deallocate original chunk if necessary
if (newChunk != chunk) {
chunk.release();
}
if (isFilterAwaitingBody(zuulReq) && zuulReq.hasCompleteBody() && !(endpoint instanceof ProxyEndpoint)) {
// whole body has arrived, resume filter chain
invokeNextStage(filter(endpoint, zuulReq));
}
}
} catch (Exception ex) {
handleException(zuulReq, endpointName, ex);
}
}
Aggregations