提交 62af99a2 编写于 作者: R Rossen Stoyanchev

Add containsKey to ServletResponseHttpHeaders

Issue: SPR-13668
上级 cf4a417f
......@@ -137,6 +137,11 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
private static final long serialVersionUID = 3410708522401046302L;
@Override
public boolean containsKey(Object key) {
return (super.containsKey(key) || (get(key) != null));
}
@Override
public String getFirst(String headerName) {
String value = servletResponse.getHeader(headerName);
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
......@@ -17,7 +17,7 @@
package org.springframework.http.server;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
......@@ -29,10 +29,13 @@ import org.springframework.http.MediaType;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Arjen Poutsma
* @author Rossen Stoyanchev
*/
public class ServletServerHttpResponseTests {
......@@ -40,12 +43,14 @@ public class ServletServerHttpResponseTests {
private MockHttpServletResponse mockResponse;
@Before
public void create() throws Exception {
mockResponse = new MockHttpServletResponse();
response = new ServletServerHttpResponse(mockResponse);
}
@Test
public void setStatusCode() throws Exception {
response.setStatusCode(HttpStatus.NOT_FOUND);
......@@ -73,7 +78,7 @@ public class ServletServerHttpResponseTests {
}
@Test
public void getHeadersFromHttpServletResponse() {
public void preExistingHeadersFromHttpServletResponse() {
String headerName = "Access-Control-Allow-Origin";
String headerValue = "localhost:8080";
......@@ -82,7 +87,8 @@ public class ServletServerHttpResponseTests {
this.response = new ServletServerHttpResponse(this.mockResponse);
assertEquals(headerValue, this.response.getHeaders().getFirst(headerName));
assertEquals(Arrays.asList(headerValue), this.response.getHeaders().get(headerName));
assertEquals(Collections.singletonList(headerValue), this.response.getHeaders().get(headerName));
assertTrue(this.response.getHeaders().containsKey(headerName));
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册