From 3a1356f553ba73a595c69af92937908c00aeee3d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 6 Jun 2020 16:56:29 +0200 Subject: [PATCH] Restore original readOnlyHttpHeaders signature for binary compatibility Closes gh-25034 --- .../org/springframework/http/HttpHeaders.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 637dc1132982..53ecb5c15a9c 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -383,7 +383,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * An empty {@code HttpHeaders} instance (immutable). * @since 5.0 */ - public static final HttpHeaders EMPTY = new ReadOnlyHttpHeaders(new HttpHeaders(new LinkedMultiValueMap<>(0))); + public static final HttpHeaders EMPTY = new ReadOnlyHttpHeaders(new LinkedMultiValueMap<>()); /** * Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match". @@ -1085,6 +1085,7 @@ public void setIfMatch(List ifMatchList) { /** * Return the value of the {@code If-Match} header. + * @throws IllegalArgumentException if parsing fails * @since 4.3 */ public List getIfMatch() { @@ -1144,6 +1145,7 @@ public void setIfNoneMatch(List ifNoneMatchList) { /** * Return the value of the {@code If-None-Match} header. + * @throws IllegalArgumentException if parsing fails */ public List getIfNoneMatch() { return getETagValuesAsList(IF_NONE_MATCH); @@ -1471,6 +1473,7 @@ public List getValuesAsList(String headerName) { * Retrieve a combined result from the field values of the ETag header. * @param headerName the header name * @return the combined result + * @throws IllegalArgumentException if parsing fails * @since 4.3 */ protected List getETagValuesAsList(String headerName) { @@ -1699,17 +1702,21 @@ public String toString() { /** - * Apply a read-only {@code HttpHeaders} wrapper around the given headers. + * Apply a read-only {@code HttpHeaders} wrapper around the given headers, + * if necessary. + * @param headers the headers to expose + * @return a read-only variant of the headers, or the original headers as-is */ - public static HttpHeaders readOnlyHttpHeaders(MultiValueMap headers) { + public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) { Assert.notNull(headers, "HttpHeaders must not be null"); - return (headers instanceof ReadOnlyHttpHeaders ? - (HttpHeaders) headers : new ReadOnlyHttpHeaders(headers)); + return (headers instanceof ReadOnlyHttpHeaders ? headers : new ReadOnlyHttpHeaders(headers.headers)); } /** * Remove any read-only wrapper that may have been previously applied around - * the given headers via {@link #readOnlyHttpHeaders(MultiValueMap)}. + * the given headers via {@link #readOnlyHttpHeaders(HttpHeaders)}. + * @param headers the headers to expose + * @return a writable variant of the headers, or the original headers as-is * @since 5.1.1 */ public static HttpHeaders writableHttpHeaders(HttpHeaders headers) {