Search in sources :

Example 26 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class PreDecorationFilterTests method sensitiveHeadersOverrideEmpty.

@Test
public void sensitiveHeadersOverrideEmpty() throws Exception {
    this.properties.setPrefix("/api");
    this.properties.setStripPrefix(true);
    this.properties.setSensitiveHeaders(Collections.singleton("x-bar"));
    this.request.setRequestURI("/api/foo/1");
    ZuulRoute route = new ZuulRoute("/foo/**", "foo");
    route.setSensitiveHeaders(Collections.<String>emptySet());
    this.routeLocator.addRoute(route);
    this.filter.run();
    RequestContext ctx = RequestContext.getCurrentContext();
    @SuppressWarnings("unchecked") Set<String> sensitiveHeaders = (Set<String>) ctx.get(ProxyRequestHelper.IGNORED_HEADERS);
    assertTrue("sensitiveHeaders is wrong: " + sensitiveHeaders, sensitiveHeaders.isEmpty());
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) HashSet(java.util.HashSet) Set(java.util.Set) RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

Example 27 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class PreDecorationFilterTests method prefixRouteWithRouteStrippingAddsHeader.

@Test
public void prefixRouteWithRouteStrippingAddsHeader() throws Exception {
    this.properties.setPrefix("/api");
    this.properties.setStripPrefix(true);
    this.request.setRequestURI("/api/foo/1");
    this.routeLocator.addRoute("/foo/**", "foo");
    this.filter.run();
    RequestContext ctx = RequestContext.getCurrentContext();
    assertEquals("/1", ctx.get(REQUEST_URI_KEY));
    assertEquals("localhost", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
    assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
    assertEquals("/api/foo", ctx.getZuulRequestHeaders().get("x-forwarded-prefix"));
    assertEquals("foo", getHeader(ctx.getOriginResponseHeaders(), "x-zuul-serviceid"));
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext) Test(org.junit.Test)

Example 28 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class EagerLoadOfZuulConfigurationTests method setTestRequestContext.

@Before
public void setTestRequestContext() {
    RequestContext context = new RequestContext();
    RequestContext.testSetCurrentContext(context);
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext) Before(org.junit.Before)

Example 29 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class LazyLoadOfZuulConfigurationTests method setTestRequestContext.

@Before
public void setTestRequestContext() {
    RequestContext context = new RequestContext();
    RequestContext.testSetCurrentContext(context);
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext) Before(org.junit.Before)

Example 30 with RequestContext

use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.

the class SendForwardFilterTests method setTestRequestcontext.

@Before
public void setTestRequestcontext() {
    RequestContext context = new RequestContext();
    RequestContext.testSetCurrentContext(context);
}
Also used : RequestContext(com.netflix.zuul.context.RequestContext) Before(org.junit.Before)

Aggregations

RequestContext (com.netflix.zuul.context.RequestContext)163 Test (org.junit.Test)59 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 ZuulRoute (org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute)24 Before (org.junit.Before)23 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 Set (java.util.Set)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)9 ZuulException (com.netflix.zuul.exception.ZuulException)7 InputStream (java.io.InputStream)7 HashSet (java.util.HashSet)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Route (org.springframework.cloud.netflix.zuul.filters.Route)7 ZuulProperties (org.springframework.cloud.netflix.zuul.filters.ZuulProperties)7 IOException (java.io.IOException)6 HttpServletRequestWrapper (com.netflix.zuul.http.HttpServletRequestWrapper)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 List (java.util.List)4 HttpHeaders (org.springframework.http.HttpHeaders)4 RateLimitCheck (com.giffing.bucket4j.spring.boot.starter.context.RateLimitCheck)3