ResourceHttpMessageWriter refactoring
Fold ResourceRegionHttpMessageWriter into ResourceHttpMessageWriter. The latter was a private helper (not meant to be exposed) and the two have much in common now sharing a number of private helper methods. The combined class does not extend AbstractServerHttpMessageConverter from which it was not using anything. Internally the combined class now delegates directly to ResourceEncoder or ResourceRegionEncoder as needed. The former is no longer wrapped with EncoderHttpMessageWriter which is not required since "resource" MediaType determination is a bit different. The consolidation makes it easy to see the entire algorithm in one place especially for server side rendering (and HTTP ranges). It also allows for consistent determination of the "resource" MediaType via MediaTypeFactory for all use cases.
This commit is contained in:
@@ -99,15 +99,9 @@ public class ResourceHandlerFunctionTests {
|
||||
return res.writeTo(exchange, HandlerStrategies.withDefaults());
|
||||
});
|
||||
|
||||
StepVerifier.create(result)
|
||||
.expectComplete()
|
||||
.verify();
|
||||
|
||||
StepVerifier.create(result).expectComplete().verify();
|
||||
StepVerifier.create(mockResponse.getBody()).expectComplete().verify();
|
||||
|
||||
StepVerifier.create(mockResponse.getBody())
|
||||
.expectComplete()
|
||||
.verify();
|
||||
assertEquals(MediaType.TEXT_PLAIN, mockResponse.getHeaders().getContentType());
|
||||
assertEquals(this.resource.contentLength(), mockResponse.getHeaders().getContentLength());
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.web.reactive.HandlerMapping;
|
||||
import org.springframework.web.reactive.accept.CompositeContentTypeResolver;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.server.MethodNotAllowedException;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
Reference in New Issue
Block a user