Java Code Examples for org.springframework.http.ReactiveHttpOutputMessage#getHeaders()
The following examples show how to use
org.springframework.http.ReactiveHttpOutputMessage#getHeaders() .
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: ResourceHttpMessageWriter.java From spring-analysis-note with MIT License | 6 votes |
private Mono<Void> writeResource(Resource resource, ResolvableType type, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) { HttpHeaders headers = message.getHeaders(); MediaType resourceMediaType = getResourceMediaType(mediaType, resource, hints); headers.setContentType(resourceMediaType); if (headers.getContentLength() < 0) { long length = lengthOf(resource); if (length != -1) { headers.setContentLength(length); } } return zeroCopy(resource, null, message, hints) .orElseGet(() -> { Mono<Resource> input = Mono.just(resource); DataBufferFactory factory = message.bufferFactory(); Flux<DataBuffer> body = this.encoder.encode(input, factory, type, resourceMediaType, hints); return message.writeWith(body); }); }
Example 2
Source File: EncoderHttpMessageWriter.java From java-technology-stack with MIT License | 6 votes |
@SuppressWarnings("unchecked") @Override public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) { MediaType contentType = updateContentType(message, mediaType); Flux<DataBuffer> body = this.encoder.encode( inputStream, message.bufferFactory(), elementType, contentType, hints); if (inputStream instanceof Mono) { HttpHeaders headers = message.getHeaders(); return Mono.from(body) .switchIfEmpty(Mono.defer(() -> { headers.setContentLength(0); return message.setComplete().then(Mono.empty()); })) .flatMap(buffer -> { headers.setContentLength(buffer.readableByteCount()); return message.writeWith(Mono.just(buffer)); }); } return (isStreamingMediaType(contentType) ? message.writeAndFlushWith(body.map(Flux::just)) : message.writeWith(body)); }
Example 3
Source File: EncoderHttpMessageWriter.java From spring-analysis-note with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) { MediaType contentType = updateContentType(message, mediaType); Flux<DataBuffer> body = this.encoder.encode( inputStream, message.bufferFactory(), elementType, contentType, hints); if (inputStream instanceof Mono) { HttpHeaders headers = message.getHeaders(); return Mono.from(body) .switchIfEmpty(Mono.defer(() -> { headers.setContentLength(0); return message.setComplete().then(Mono.empty()); })) .flatMap(buffer -> { headers.setContentLength(buffer.readableByteCount()); return message.writeWith(Mono.just(buffer) .doOnDiscard(PooledDataBuffer.class, PooledDataBuffer::release)); }); } if (isStreamingMediaType(contentType)) { return message.writeAndFlushWith(body.map(buffer -> Mono.just(buffer).doOnDiscard(PooledDataBuffer.class, PooledDataBuffer::release))); } return message.writeWith(body); }
Example 4
Source File: ResourceHttpMessageWriter.java From java-technology-stack with MIT License | 5 votes |
private Mono<Void> writeResource(Resource resource, ResolvableType type, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) { HttpHeaders headers = message.getHeaders(); MediaType resourceMediaType = getResourceMediaType(mediaType, resource, hints); headers.setContentType(resourceMediaType); if (headers.getContentLength() < 0) { long length = lengthOf(resource); if (length != -1) { headers.setContentLength(length); } } return zeroCopy(resource, null, message, hints) .orElseGet(() -> { Mono<Resource> input = Mono.just(resource); DataBufferFactory factory = message.bufferFactory(); Flux<DataBuffer> body = this.encoder.encode(input, factory, type, resourceMediaType, hints); return message.writeWith(body); }); }