use of de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute in project spring-boot-admin by codecentric.
the class ApplicationHeadersFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
String requestURI = this.urlPathHelper.getPathWithinApplication(ctx.getRequest());
ApplicationRoute route = this.routeLocator.getMatchingRoute(requestURI);
if (route != null) {
HttpHeaders headers = headersProvider.getHeaders(route.getApplication());
for (Entry<String, List<String>> header : headers.entrySet()) {
ctx.addZuulRequestHeader(header.getKey(), header.getValue().get(0));
}
}
return null;
}
use of de.codecentric.boot.admin.zuul.ApplicationRouteLocator.ApplicationRoute in project spring-boot-admin by codecentric.
the class ApplicationHeadersFilterTest method test_add_headers_on_matching_route_only.
@Test
public void test_add_headers_on_matching_route_only() {
Application application = Application.create("test").withHealthUrl("/health").build();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("test", "qwertz");
when(routeLocator.getMatchingRoute("/health")).thenReturn(new ApplicationRoute(application, null, null, null, null));
when(headerProvider.getHeaders(application)).thenReturn(httpHeaders);
RequestContext context = creteRequestContext("/health");
RequestContext.testSetCurrentContext(context);
filter.run();
assertThat(context.getZuulRequestHeaders().get("test"), is("qwertz"));
context = creteRequestContext("/foobar");
RequestContext.testSetCurrentContext(context);
filter.run();
assertThat(context.getZuulRequestHeaders().get("test"), nullValue());
}
Aggregations