Consistent handling of null header values in HttpHeaders

Issue: SPR-17588
This commit is contained in:
Juergen Hoeller
2018-12-12 11:16:45 +01:00
parent 4b4503085a
commit 5bbbc82e19
6 changed files with 69 additions and 52 deletions

View File

@@ -38,8 +38,8 @@ import java.util.TimeZone;
import org.hamcrest.Matchers;
import org.junit.Test;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
import static org.hamcrest.Matchers.is;
import static java.time.format.DateTimeFormatter.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
@@ -355,11 +355,18 @@ public class HttpHeadersTests {
assertEquals("Invalid Cache-Control header", "no-cache", headers.getFirst("cache-control"));
}
@Test
public void cacheControlEmpty() {
headers.setCacheControl(CacheControl.empty());
assertNull("Invalid Cache-Control header", headers.getCacheControl());
assertNull("Invalid Cache-Control header", headers.getFirst("cache-control"));
}
@Test
public void cacheControlAllValues() {
headers.add(HttpHeaders.CACHE_CONTROL, "max-age=1000, public");
headers.add(HttpHeaders.CACHE_CONTROL, "s-maxage=1000");
assertThat(headers.getCacheControl(), is("max-age=1000, public, s-maxage=1000"));
assertEquals("max-age=1000, public, s-maxage=1000", headers.getCacheControl());
}
@Test
@@ -375,7 +382,7 @@ public class HttpHeadersTests {
@Test // SPR-11917
public void getAllowEmptySet() {
headers.setAllow(Collections.<HttpMethod> emptySet());
headers.setAllow(Collections.emptySet());
assertThat(headers.getAllow(), Matchers.emptyCollectionOf(HttpMethod.class));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@@ -29,7 +29,7 @@ import static org.mockito.Mockito.*;
*/
public class SimpleClientHttpRequestFactoryTests {
@Test // SPR-13225
@Test // SPR-13225
public void headerWithNullValue() {
HttpURLConnection urlConnection = mock(HttpURLConnection.class);
HttpHeaders headers = new HttpHeaders();