List of usage examples for org.springframework.http HttpHeaders HOST
String HOST
To view the source code for org.springframework.http HttpHeaders HOST.
Click Source Link
From source file:org.springframework.cloud.gateway.filter.factory.RetryGatewayFilterFactoryIntegrationTests.java
@Test public void retryFilterFailure() { testClient.get().uri("/retryalwaysfail?key=getjavafailure&count=4") .header(HttpHeaders.HOST, "www.retryjava.org").exchange().expectStatus().is5xxServerError() .expectBody(String.class).consumeWith(result -> { assertThat(result.getResponseBody()).contains("permanently broken"); });//from w w w. j a v a 2s . c om }
From source file:org.springframework.cloud.gateway.filter.factory.RetryGatewayFilterFactoryIntegrationTests.java
@Test public void retryFilterGetJavaDsl() { testClient.get().uri("/retry?key=getjava&count=2").header(HttpHeaders.HOST, "www.retryjava.org").exchange() .expectStatus().isOk().expectBody(String.class).isEqualTo("2"); }
From source file:org.springframework.cloud.gateway.filter.factory.RetryGatewayFilterFactoryIntegrationTests.java
@Test @SuppressWarnings("unchecked") public void retryFilterLoadBalancedWithMultipleServers() { String host = "www.retrywithloadbalancer.org"; testClient.get().uri("/get").header(HttpHeaders.HOST, host).exchange().expectStatus().isOk() .expectBody(Map.class).consumeWith(res -> { Map body = res.getResponseBody(); assertThat(body).isNotNull(); Map<String, Object> headers = (Map<String, Object>) body.get("headers"); assertThat(headers).containsEntry("X-Forwarded-Host", host); });//from ww w. j a v a 2 s .c o m }
From source file:org.springframework.cloud.netflix.zuul.filters.pre.PreDecorationFilter.java
@Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); final String requestURI = this.urlPathHelper.getPathWithinApplication(ctx.getRequest()); Route route = this.routeLocator.getMatchingRoute(requestURI); if (route != null) { String location = route.getLocation(); if (location != null) { ctx.put(REQUEST_URI_KEY, route.getPath()); ctx.put(PROXY_KEY, route.getId()); if (!route.isCustomSensitiveHeaders()) { this.proxyRequestHelper .addIgnoredHeaders(this.properties.getSensitiveHeaders().toArray(new String[0])); } else { this.proxyRequestHelper.addIgnoredHeaders(route.getSensitiveHeaders().toArray(new String[0])); }//from www. ja v a2s. co m if (route.getRetryable() != null) { ctx.put(RETRYABLE_KEY, route.getRetryable()); } if (location.startsWith(HTTP_SCHEME + ":") || location.startsWith(HTTPS_SCHEME + ":")) { ctx.setRouteHost(getUrl(location)); ctx.addOriginResponseHeader(SERVICE_HEADER, location); } else if (location.startsWith(FORWARD_LOCATION_PREFIX)) { ctx.set(FORWARD_TO_KEY, StringUtils .cleanPath(location.substring(FORWARD_LOCATION_PREFIX.length()) + route.getPath())); ctx.setRouteHost(null); return null; } else { // set serviceId for use in filters.route.RibbonRequest ctx.set(SERVICE_ID_KEY, location); ctx.setRouteHost(null); ctx.addOriginResponseHeader(SERVICE_ID_HEADER, location); } if (this.properties.isAddProxyHeaders()) { addProxyHeaders(ctx, route); String xforwardedfor = ctx.getRequest().getHeader(X_FORWARDED_FOR_HEADER); String remoteAddr = ctx.getRequest().getRemoteAddr(); if (xforwardedfor == null) { xforwardedfor = remoteAddr; } else if (!xforwardedfor.contains(remoteAddr)) { // Prevent duplicates xforwardedfor += ", " + remoteAddr; } ctx.addZuulRequestHeader(X_FORWARDED_FOR_HEADER, xforwardedfor); } if (this.properties.isAddHostHeader()) { ctx.addZuulRequestHeader(HttpHeaders.HOST, toHostHeader(ctx.getRequest())); } } } else { log.warn("No route found for uri: " + requestURI); String fallBackUri = requestURI; String fallbackPrefix = this.dispatcherServletPath; // default fallback // servlet is // DispatcherServlet if (RequestUtils.isZuulServletRequest()) { // remove the Zuul servletPath from the requestUri log.debug("zuulServletPath=" + this.properties.getServletPath()); fallBackUri = fallBackUri.replaceFirst(this.properties.getServletPath(), ""); log.debug("Replaced Zuul servlet path:" + fallBackUri); } else { // remove the DispatcherServlet servletPath from the requestUri log.debug("dispatcherServletPath=" + this.dispatcherServletPath); fallBackUri = fallBackUri.replaceFirst(this.dispatcherServletPath, ""); log.debug("Replaced DispatcherServlet servlet path:" + fallBackUri); } if (!fallBackUri.startsWith("/")) { fallBackUri = "/" + fallBackUri; } String forwardURI = fallbackPrefix + fallBackUri; forwardURI = forwardURI.replaceAll("//", "/"); ctx.set(FORWARD_TO_KEY, forwardURI); } return null; }