From 6e3f974951b71b6566392f58135b71ffca6fd135 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 8 Jan 2019 00:32:27 +0100 Subject: [PATCH] HttpHeaders.writableHttpHeaders properly handles HttpHeaders.EMPTY Issue: SPR-17633 --- .../java/org/springframework/http/HttpHeaders.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 7fffd16141..bb46958e29 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-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -1694,11 +1694,15 @@ public class HttpHeaders implements MultiValueMap, Serializable } /** - * Return a {@code HttpHeaders} object that can read and written to. + * Return a {@code HttpHeaders} object that can be read and written to. + * @since 5.1.1 */ public static HttpHeaders writableHttpHeaders(HttpHeaders headers) { Assert.notNull(headers, "HttpHeaders must not be null"); - if (headers instanceof ReadOnlyHttpHeaders) { + if (headers == EMPTY) { + return new HttpHeaders(); + } + else if (headers instanceof ReadOnlyHttpHeaders) { return new HttpHeaders(headers.headers); } else {