use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class SendResponseFilterTests method testCloseResponseDataStream.
@Test
public void testCloseResponseDataStream() throws Exception {
HttpServletResponse response = mock(HttpServletResponse.class);
InputStream mockStream = spy(new ByteArrayInputStream("Hello\n".getBytes("UTF-8")));
RequestContext context = new RequestContext();
context.setRequest(new MockHttpServletRequest());
context.setResponse(response);
context.setResponseDataStream(mockStream);
Closeable zuulResponse = mock(Closeable.class);
context.set("zuulResponse", zuulResponse);
RequestContext.testSetCurrentContext(context);
when(response.getOutputStream()).thenReturn(mock(ServletOutputStream.class));
SendResponseFilter filter = new SendResponseFilter();
filter.run();
verify(mockStream).close();
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method xForwardedPortOnlyAppends.
@Test
public void xForwardedPortOnlyAppends() throws Exception {
this.properties.setPrefix("/api");
this.request.setRequestURI("/api/foo/1");
this.request.setRemoteAddr("5.6.7.8");
this.request.setServerPort(8080);
this.request.addHeader("X-Forwarded-Port", "456");
this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("456,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method setTestRequestContext.
private void setTestRequestContext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method xForwardedProtoHttpOnlyAppends.
@Test
public void xForwardedProtoHttpOnlyAppends() throws Exception {
this.properties.setPrefix("/api");
this.request.setRequestURI("/api/foo/1");
this.request.setRemoteAddr("5.6.7.8");
this.request.setServerPort(8080);
this.request.addHeader("X-Forwarded-Proto", "http");
this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("80,8080", ctx.getZuulRequestHeaders().get("x-forwarded-port"));
assertEquals("http,http", ctx.getZuulRequestHeaders().get("x-forwarded-proto"));
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method hostHeaderSet.
@Test
public void hostHeaderSet() throws Exception {
this.properties.setPrefix("/api");
this.properties.setAddHostHeader(true);
this.request.setRequestURI("/api/foo/1");
this.request.setRemoteAddr("5.6.7.8");
this.request.setServerPort(8080);
this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", "foo", null, false, null, null));
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("x-forwarded-host"));
assertEquals("localhost:8080", ctx.getZuulRequestHeaders().get("host"));
}
Aggregations