use of com.netflix.zuul.context.RequestContext in project cetc by DiscoverForever.
the class RateLimitingFilter method apiLimitExceeded.
/**
* Create a Zuul response error when the API limit is exceeded.
*/
private void apiLimitExceeded() {
RequestContext ctx = RequestContext.getCurrentContext();
ctx.setResponseStatusCode(HttpStatus.TOO_MANY_REQUESTS.value());
if (ctx.getResponseBody() == null) {
ctx.setResponseBody("API rate limit exceeded");
ctx.setSendZuulResponse(false);
}
}
use of com.netflix.zuul.context.RequestContext in project cetc by DiscoverForever.
the class TokenRelayFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Set<String> headers = (Set<String>) ctx.get("ignoredHeaders");
// JWT tokens should be relayed to the resource servers
headers.remove("authorization");
return null;
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method routeNotFoundZuulRequestDispatcherServletSpecialPath.
@Test
public void routeNotFoundZuulRequestDispatcherServletSpecialPath() throws Exception {
setTestRequestContext();
RequestContext ctx = RequestContext.getCurrentContext();
RequestContext.getCurrentContext().setZuulEngineRan();
this.request.setRequestURI("/zuul/api/bar/1");
ctx.setRequest(this.request);
this.properties.setPrefix("/api");
this.properties.setStripPrefix(true);
this.properties.setServletPath("/zuul");
this.properties.setAddProxyHeaders(true);
this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
this.filter = new PreDecorationFilter(this.routeLocator, "/special", this.properties, this.proxyRequestHelper);
this.filter.run();
assertEquals("/special/api/bar/1", ctx.get(FORWARD_TO_KEY));
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method routeNotFoundZuulRequest.
@Test
public void routeNotFoundZuulRequest() throws Exception {
setTestRequestContext();
RequestContext ctx = RequestContext.getCurrentContext();
RequestContext.getCurrentContext().setZuulEngineRan();
this.request.setRequestURI("/zuul/api/bar/1");
ctx.setRequest(this.request);
this.properties.setPrefix("/api");
this.properties.setStripPrefix(true);
this.properties.setServletPath("/zuul");
this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
this.filter.run();
assertEquals("/api/bar/1", ctx.get(FORWARD_TO_KEY));
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method routeNotFoundDispatcherServletSpecialPath.
@Test
public void routeNotFoundDispatcherServletSpecialPath() throws Exception {
this.properties.setPrefix("/api");
this.properties.setStripPrefix(true);
this.properties.setAddProxyHeaders(true);
this.routeLocator.addRoute(new ZuulRoute("foo", "/foo/**", null, "forward:/foo", true, null, null));
this.filter = new PreDecorationFilter(this.routeLocator, "/special", this.properties, this.proxyRequestHelper);
this.request.setRequestURI("/api/bar/1");
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
assertEquals("/special/api/bar/1", ctx.get(FORWARD_TO_KEY));
}
Aggregations