Search in sources :

Example 1 with HttpQueryParams

use of com.netflix.zuul.message.http.HttpQueryParams in project zuul by Netflix.

the class OriginResponseReceiver method pathAndQueryString.

private static String pathAndQueryString(HttpRequestMessage request) {
    // parsing the params cleans up any empty/null params using the logic of the HttpQueryParams class
    final HttpQueryParams cleanParams = HttpQueryParams.parse(request.getQueryParams().toEncodedString());
    final String cleanQueryStr = cleanParams.toEncodedString();
    if (cleanQueryStr == null || cleanQueryStr.isEmpty()) {
        return request.getPath();
    } else {
        return request.getPath() + "?" + cleanParams.toEncodedString();
    }
}
Also used : HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams)

Example 2 with HttpQueryParams

use of com.netflix.zuul.message.http.HttpQueryParams in project zuul by Netflix.

the class ZuulFilterChainRunnerTest method before.

@Before
public void before() {
    SessionContext context = new SessionContext();
    Headers headers = new Headers();
    ChannelHandlerContext chc = mock(ChannelHandlerContext.class);
    when(chc.executor()).thenReturn(ImmediateEventExecutor.INSTANCE);
    context.put(NETTY_SERVER_CHANNEL_HANDLER_CONTEXT, chc);
    request = new HttpRequestMessageImpl(context, "http", "GET", "/foo/bar", new HttpQueryParams(), headers, "127.0.0.1", "http", 8080, "server123");
    request.storeInboundRequest();
    response = new HttpResponseMessageImpl(context, request, 200);
}
Also used : Headers(com.netflix.zuul.message.Headers) HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) HttpResponseMessageImpl(com.netflix.zuul.message.http.HttpResponseMessageImpl) SessionContext(com.netflix.zuul.context.SessionContext) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpRequestMessageImpl(com.netflix.zuul.message.http.HttpRequestMessageImpl) Before(org.junit.Before)

Example 3 with HttpQueryParams

use of com.netflix.zuul.message.http.HttpQueryParams 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));
}
Also used : HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) Headers(com.netflix.zuul.message.Headers) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) HttpResponseMessageImpl(com.netflix.zuul.message.http.HttpResponseMessageImpl) SessionContext(com.netflix.zuul.context.SessionContext) HttpRequestMessageImpl(com.netflix.zuul.message.http.HttpRequestMessageImpl) Test(org.junit.Test)

Example 4 with HttpQueryParams

use of com.netflix.zuul.message.http.HttpQueryParams in project zuul by Netflix.

the class DebugTest method setup.

@Before
public void setup() {
    ctx = new SessionContext();
    headers = new Headers();
    headers.add("lah", "deda");
    params = new HttpQueryParams();
    params.add("k1", "v1");
    request = new HttpRequestBuilder(ctx).withMethod(HttpMethod.POST).withUri("/some/where").withHeaders(headers).withQueryParams(params).build();
    request.setBodyAsText("some text");
    request.storeInboundRequest();
    response = new HttpResponseMessageImpl(ctx, headers, request, 200);
    response.setBodyAsText("response text");
}
Also used : Headers(com.netflix.zuul.message.Headers) HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) HttpResponseMessageImpl(com.netflix.zuul.message.http.HttpResponseMessageImpl) HttpRequestBuilder(com.netflix.zuul.message.util.HttpRequestBuilder) Before(org.junit.Before)

Example 5 with HttpQueryParams

use of com.netflix.zuul.message.http.HttpQueryParams in project zuul by Netflix.

the class SurgicalDebugFilter method apply.

@Override
public HttpRequestMessage apply(HttpRequestMessage request) {
    DynamicStringProperty routeVip = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_VIP, null);
    DynamicStringProperty routeHost = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_HOST, null);
    SessionContext ctx = request.getContext();
    if (routeVip.get() != null || routeHost.get() != null) {
        ctx.set("routeHost", routeHost.get());
        ctx.set("routeVIP", routeVip.get());
        request.getHeaders().set(ZuulHeaders.X_ZUUL_SURGICAL_FILTER, "true");
        HttpQueryParams queryParams = request.getQueryParams();
        queryParams.set("debugRequest", "true");
        ctx.setDebugRequest(true);
        ctx.set("zuulToZuul", true);
    }
    return request;
}
Also used : HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) DynamicStringProperty(com.netflix.config.DynamicStringProperty) SessionContext(com.netflix.zuul.context.SessionContext)

Aggregations

HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)6 SessionContext (com.netflix.zuul.context.SessionContext)4 Headers (com.netflix.zuul.message.Headers)3 HttpResponseMessageImpl (com.netflix.zuul.message.http.HttpResponseMessageImpl)3 HttpRequestMessageImpl (com.netflix.zuul.message.http.HttpRequestMessageImpl)2 Before (org.junit.Before)2 DynamicStringProperty (com.netflix.config.DynamicStringProperty)1 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)1 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)1 HttpRequestBuilder (com.netflix.zuul.message.util.HttpRequestBuilder)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 StringTokenizer (java.util.StringTokenizer)1 Test (org.junit.Test)1