use of org.springframework.web.reactive.accept.CompositeContentTypeResolver in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method getMediaTypeWithFavorPathExtensionOff.
// SPR-14577
@Test
public void getMediaTypeWithFavorPathExtensionOff() throws Exception {
CompositeContentTypeResolver contentTypeResolver = new RequestedContentTypeResolverBuilder().favorPathExtension(false).build();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceWebHandler handler = new ResourceWebHandler();
handler.setLocations(paths);
handler.setContentTypeResolver(contentTypeResolver);
handler.afterPropertiesSet();
handler.afterSingletonsInstantiated();
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("Accept", "application/json,text/plain,*/*").toExchange();
setPathWithinHandlerMapping(exchange, "foo.html");
handler.handle(exchange).block(TIMEOUT);
assertEquals(MediaType.TEXT_HTML, exchange.getResponse().getHeaders().getContentType());
}
use of org.springframework.web.reactive.accept.CompositeContentTypeResolver in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method getResourceWithRegisteredMediaType.
// SPR-13658
@Test
public void getResourceWithRegisteredMediaType() throws Exception {
CompositeContentTypeResolver contentTypeResolver = new RequestedContentTypeResolverBuilder().mediaType("css", new MediaType("foo", "bar")).build();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceWebHandler handler = new ResourceWebHandler();
handler.setLocations(paths);
handler.setContentTypeResolver(contentTypeResolver);
handler.afterPropertiesSet();
handler.afterSingletonsInstantiated();
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
setPathWithinHandlerMapping(exchange, "foo.css");
handler.handle(exchange).block(TIMEOUT);
assertEquals(MediaType.parseMediaType("foo/bar"), exchange.getResponse().getHeaders().getContentType());
assertResponseBody(exchange, "h1 { color:red; }");
}
Aggregations