Java Code Examples for com.netflix.zuul.context.RequestContext#getZuulResponseHeaders()
The following examples show how to use
com.netflix.zuul.context.RequestContext#getZuulResponseHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlashFilterTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Test public void proxyStartsWithSlash() throws Exception { final RequestContext ctx = RequestContext.getCurrentContext(); ctx.set(PROXY_KEY, "/ui/service"); this.filter.run(); String location = ""; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); if (zuulResponseHeaders != null) { for (Pair<String, String> header : zuulResponseHeaders) { if (header.first().equals("Location")) location = header.second(); } } assertEquals("/ui/service/", location); assertEquals(302, ctx.getResponseStatusCode()); }
Example 2
Source File: SlashFilterTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Test public void proxyEndsWithSlash() throws Exception { final RequestContext ctx = RequestContext.getCurrentContext(); ctx.set(PROXY_KEY, "ui/service/"); this.filter.run(); String location = ""; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); if (zuulResponseHeaders != null) { for (Pair<String, String> header : zuulResponseHeaders) { if (header.first().equals("Location")) location = header.second(); } } assertEquals("/ui/service/", location); assertEquals(302, ctx.getResponseStatusCode()); }
Example 3
Source File: SlashFilterTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Test public void proxyIsNull() throws Exception { final RequestContext ctx = RequestContext.getCurrentContext(); ctx.set(PROXY_KEY, null); this.filter.run(); Boolean isLocation = false; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); if (zuulResponseHeaders != null) { for (Pair<String, String> header : zuulResponseHeaders) { if (header.first().equals("Location")) isLocation = true; } } assertEquals(false, isLocation); assertEquals(500, ctx.getResponseStatusCode()); }
Example 4
Source File: SlashFilterTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Test public void proxyIsEmpty() throws Exception { final RequestContext ctx = RequestContext.getCurrentContext(); ctx.set(PROXY_KEY, ""); this.filter.run(); Boolean isLocation = false; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); if (zuulResponseHeaders != null) { for (Pair<String, String> header : zuulResponseHeaders) { if (header.first().equals("Location")) isLocation = true; } } assertEquals(false, isLocation); assertEquals(500, ctx.getResponseStatusCode()); }
Example 5
Source File: BaseFilter.java From convergent-ui with Apache License 2.0 | 6 votes |
protected MimeType getMimeType(RequestContext context) { List<Pair<String, String>> headers = context.getZuulResponseHeaders(); String contentType = null; for (Pair<String, String> pair : headers) { if ("content-type".equalsIgnoreCase(pair.first())) { contentType = pair.second(); break; } } if (contentType != null) { MimeType type = MimeType.valueOf(contentType); return type; } return null; }
Example 6
Source File: SlashFilterTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Test public void responseIsModified() throws Exception { final RequestContext ctx = RequestContext.getCurrentContext(); this.filter.run(); String location = ""; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); if (zuulResponseHeaders != null) { for (Pair<String, String> header : zuulResponseHeaders) { if (header.first().equals("Location")) location = header.second(); } } assertEquals("/ui/service/", location); assertEquals(302, ctx.getResponseStatusCode()); }
Example 7
Source File: LocationHeaderRewritingFilter.java From pulsar-manager with Apache License 2.0 | 5 votes |
private Pair<String, String> locationHeader(RequestContext ctx) { if (ctx.getZuulResponseHeaders() != null) { for (Pair<String, String> pair : ctx.getZuulResponseHeaders()) { if (pair.first().equals(LOCATION_HEADER)) { return pair; } } } return null; }
Example 8
Source File: CORSInterceptorService.java From heimdall with Apache License 2.0 | 5 votes |
public void executeCorsPostFilter(Map<String, String> cors) { RequestContext ctx = RequestContext.getCurrentContext(); HttpServletResponse response = ctx.getResponse(); List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); List<String> headersFromResponse = zuulResponseHeaders.stream().map(Pair::first).collect(Collectors.toList()); cors.entrySet() .stream() .filter(entry -> !headersFromResponse.contains(entry.getKey())) .forEach(entry -> response.setHeader(entry.getKey(), entry.getValue())); }
Example 9
Source File: CORSInterceptorService.java From heimdall with Apache License 2.0 | 5 votes |
private void addHeadersToResponseOptions(Map<String, String> cors) { RequestContext ctx = RequestContext.getCurrentContext(); List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); List<String> headersFromResponse = zuulResponseHeaders.stream().map(Pair::first).collect(Collectors.toList()); cors.entrySet() .stream() .filter(entry -> !headersFromResponse.contains(entry.getKey())) .forEach(entry -> ctx.addZuulResponseHeader(entry.getKey(), entry.getValue())); }
Example 10
Source File: ProxyRedirectFilter.java From spring-cloud-netflix-zuul-websocket with Apache License 2.0 | 5 votes |
@Override public boolean shouldFilter() { RequestContext ctx = RequestContext.getCurrentContext(); boolean isRedirect = ctx.getResponseStatusCode() == 301 || ctx.getResponseStatusCode() == 302; if (!isRedirect) return false; boolean hasCorrectLocation = false; List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); for (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) { if ("Location".equalsIgnoreCase(zuulResponseHeader.first())) { HttpServletRequest request = ctx.getRequest(); String path = urlPathHelper.getPathWithinApplication(request); Route route = routeLocator.getMatchingRoute(path); UriComponents redirectTo = ServletUriComponentsBuilder .fromHttpUrl(zuulResponseHeader.second()).build(); UriComponents routeLocation = ServletUriComponentsBuilder .fromHttpUrl(route.getLocation()).build(); if (redirectTo.getHost().equalsIgnoreCase(routeLocation.getHost()) && redirectTo.getPort() == routeLocation.getPort()) { String toLocation = ServletUriComponentsBuilder .fromHttpUrl(zuulResponseHeader.second()) .host(request.getServerName()) .port(request.getServerPort()) .replacePath( buildRoutePath(route, zuulResponseHeader.second())) .build().toUriString(); ctx.put(REDIRECT_TO_URL, toLocation); hasCorrectLocation = true; break; } } } return hasCorrectLocation; }
Example 11
Source File: ProxyRedirectFilter.java From spring-cloud-netflix-zuul-websocket with Apache License 2.0 | 5 votes |
@Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); List<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders(); for (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) { if ("Location".equalsIgnoreCase(zuulResponseHeader.first())) { zuulResponseHeader.setSecond(ctx.get(REDIRECT_TO_URL).toString()); break; } } return null; }