Polish
See gh-24238
This commit is contained in:
@@ -1522,6 +1522,22 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the well-known {@code "Content-*"} HTTP headers.
|
||||
* <p>Such headers should be cleared from the response if the intended
|
||||
* body can't be written due to errors.
|
||||
* @since 5.2.3
|
||||
*/
|
||||
public void clearContentHeaders() {
|
||||
this.headers.remove(HttpHeaders.CONTENT_DISPOSITION);
|
||||
this.headers.remove(HttpHeaders.CONTENT_ENCODING);
|
||||
this.headers.remove(HttpHeaders.CONTENT_LANGUAGE);
|
||||
this.headers.remove(HttpHeaders.CONTENT_LENGTH);
|
||||
this.headers.remove(HttpHeaders.CONTENT_LOCATION);
|
||||
this.headers.remove(HttpHeaders.CONTENT_RANGE);
|
||||
this.headers.remove(HttpHeaders.CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a combined result from the field values of the ETag header.
|
||||
* @param headerName the header name
|
||||
@@ -1827,22 +1843,6 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
return new String(encodedBytes, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the well-known {@code "Content-*"} HTTP headers from the given instance.
|
||||
* <p>Such headers should be cleared, if possible, from the response if the intended
|
||||
* body can't be written due to errors.
|
||||
* @since 5.2.3
|
||||
*/
|
||||
public static void clearContentHeaders(HttpHeaders headers) {
|
||||
headers.remove(HttpHeaders.CONTENT_DISPOSITION);
|
||||
headers.remove(HttpHeaders.CONTENT_ENCODING);
|
||||
headers.remove(HttpHeaders.CONTENT_LANGUAGE);
|
||||
headers.remove(HttpHeaders.CONTENT_LENGTH);
|
||||
headers.remove(HttpHeaders.CONTENT_LOCATION);
|
||||
headers.remove(HttpHeaders.CONTENT_RANGE);
|
||||
headers.remove(HttpHeaders.CONTENT_TYPE);
|
||||
}
|
||||
|
||||
// Package-private: used in ResponseCookie
|
||||
static String formatDate(long date) {
|
||||
Instant instant = Instant.ofEpochMilli(date);
|
||||
|
||||
@@ -75,6 +75,11 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContentHeaders() {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> get(Object key) {
|
||||
List<String> values = this.headers.get(key);
|
||||
|
||||
@@ -182,22 +182,16 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
||||
return ((Mono<? extends DataBuffer>) body).flatMap(buffer ->
|
||||
doCommit(() -> writeWithInternal(Mono.just(buffer)))
|
||||
.doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release))
|
||||
.doOnError(t -> clearContentHeaders());
|
||||
.doOnError(t -> this.getHeaders().clearContentHeaders());
|
||||
}
|
||||
return new ChannelSendOperator<>(body, inner -> doCommit(() -> writeWithInternal(inner)))
|
||||
.doOnError(t -> clearContentHeaders());
|
||||
.doOnError(t -> this.getHeaders().clearContentHeaders());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) {
|
||||
return new ChannelSendOperator<>(body, inner -> doCommit(() -> writeAndFlushWithInternal(inner)))
|
||||
.doOnError(t -> clearContentHeaders());
|
||||
}
|
||||
|
||||
private void clearContentHeaders() {
|
||||
if (!this.isCommitted()) {
|
||||
HttpHeaders.clearContentHeaders(this.getHeaders());
|
||||
}
|
||||
.doOnError(t -> this.getHeaders().clearContentHeaders());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user