Search in sources :

Example 11 with HttpRequestMessage

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;
}
Also used : HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) Headers(com.netflix.zuul.message.Headers)

Example 12 with HttpRequestMessage

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()));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) Test(org.junit.Test)

Example 13 with HttpRequestMessage

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);
}
Also used : HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) HttpRequestInfo(com.netflix.zuul.message.http.HttpRequestInfo)

Example 14 with HttpRequestMessage

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;
}
Also used : HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) MissingEndpointHandlingFilter(com.netflix.zuul.filters.endpoint.MissingEndpointHandlingFilter) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) SessionContext(com.netflix.zuul.context.SessionContext)

Example 15 with HttpRequestMessage

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);
    }
}
Also used : HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) ProxyEndpoint(com.netflix.zuul.filters.endpoint.ProxyEndpoint) HttpContent(io.netty.handler.codec.http.HttpContent) TaskCloseable(io.perfmark.TaskCloseable)

Aggregations

HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)16 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)8 SessionContext (com.netflix.zuul.context.SessionContext)6 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4 HttpContent (io.netty.handler.codec.http.HttpContent)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4 TaskCloseable (io.perfmark.TaskCloseable)4 Test (org.junit.Test)4 ProxyEndpoint (com.netflix.zuul.filters.endpoint.ProxyEndpoint)3 ByteBuf (io.netty.buffer.ByteBuf)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)2 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 Headers (com.netflix.zuul.message.Headers)2 HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)2 HttpRequestMessageImpl (com.netflix.zuul.message.http.HttpRequestMessageImpl)2 PassportLoggingHandler (com.netflix.zuul.netty.insights.PassportLoggingHandler)2 CurrentPassport (com.netflix.zuul.passport.CurrentPassport)2 HttpRequestEncoder (io.netty.handler.codec.http.HttpRequestEncoder)2 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)2