Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
f588ab05
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f588ab05
编写于
3月 10, 2010
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added readonly version of HttpHeaders
上级
2dd11343
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
12 deletion
+42
-12
org.springframework.web/src/main/java/org/springframework/http/HttpHeaders.java
...b/src/main/java/org/springframework/http/HttpHeaders.java
+34
-3
org.springframework.web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java
...pringframework/http/client/AbstractClientHttpRequest.java
+3
-4
org.springframework.web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java
...pringframework/http/server/ServletServerHttpResponse.java
+3
-3
org.springframework.web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java
...ework/http/client/AbstractHttpRequestFactoryTestCase.java
+2
-2
未找到文件。
org.springframework.web/src/main/java/org/springframework/http/HttpHeaders.java
浏览文件 @
f588ab05
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -26,13 +26,13 @@ import java.util.Collections;
import
java.util.Date
;
import
java.util.EnumSet
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TimeZone
;
import
java.util.LinkedHashMap
;
import
org.springframework.util.Assert
;
import
org.springframework.util.LinkedCaseInsensitiveMap
;
...
...
@@ -93,9 +93,40 @@ public class HttpHeaders implements MultiValueMap<String, String> {
private
static
TimeZone
GMT
=
TimeZone
.
getTimeZone
(
"GMT"
);
private
final
Map
<
String
,
List
<
String
>>
headers
;
/**
* Private constructor that can create read-only {@code HttpHeader} instances.
*/
private
HttpHeaders
(
Map
<
String
,
List
<
String
>>
headers
,
boolean
readOnly
)
{
Assert
.
notNull
(
headers
,
"'headers' must not be null"
);
if
(
readOnly
)
{
Map
<
String
,
List
<
String
>>
map
=
new
LinkedCaseInsensitiveMap
<
List
<
String
>>(
headers
.
size
(),
Locale
.
ENGLISH
);
for
(
Entry
<
String
,
List
<
String
>>
entry
:
headers
.
entrySet
())
{
List
<
String
>
values
=
Collections
.
unmodifiableList
(
entry
.
getValue
());
map
.
put
(
entry
.
getKey
(),
values
);
}
this
.
headers
=
Collections
.
unmodifiableMap
(
map
);
}
else
{
this
.
headers
=
headers
;
}
}
private
final
Map
<
String
,
List
<
String
>>
headers
=
new
LinkedCaseInsensitiveMap
<
List
<
String
>>(
8
);
/**
* Constructs a new instance of the {@code HttpHeaders} object.
*/
public
HttpHeaders
()
{
this
(
new
LinkedCaseInsensitiveMap
<
List
<
String
>>(
8
,
Locale
.
ENGLISH
),
false
);
}
/**
* Returns {@code HttpHeaders} object that can only be read, not written to.
*/
public
static
HttpHeaders
readOnlyHttpHeaders
(
HttpHeaders
headers
)
{
return
new
HttpHeaders
(
headers
,
true
);
}
/**
* Set the list of acceptable {@linkplain MediaType media types}, as specified by the {@code Accept} header.
...
...
org.springframework.web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java
浏览文件 @
f588ab05
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -20,8 +20,8 @@ import java.io.ByteArrayOutputStream;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
org.springframework.util.Assert
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.util.Assert
;
/**
* Abstract base for {@link ClientHttpRequest} that makes sure that headers and body are not written multiple times.
...
...
@@ -39,8 +39,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
public
final
HttpHeaders
getHeaders
()
{
checkExecuted
();
return
this
.
headers
;
return
executed
?
HttpHeaders
.
readOnlyHttpHeaders
(
headers
)
:
this
.
headers
;
}
public
final
OutputStream
getBody
()
throws
IOException
{
...
...
org.springframework.web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java
浏览文件 @
f588ab05
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -22,9 +22,9 @@ import java.util.List;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.util.Assert
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.util.Assert
;
/**
* {@link ServerHttpResponse} implementation that is based on a {@link HttpServletResponse}.
...
...
@@ -56,7 +56,7 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
}
public
HttpHeaders
getHeaders
()
{
return
this
.
headers
;
return
headersWritten
?
HttpHeaders
.
readOnlyHttpHeaders
(
headers
)
:
this
.
headers
;
}
public
OutputStream
getBody
()
throws
IOException
{
...
...
org.springframework.web/src/test/java/org/springframework/http/client/AbstractHttpRequestFactoryTestCase.java
浏览文件 @
f588ab05
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -124,7 +124,7 @@ public abstract class AbstractHttpRequestFactoryTestCase {
}
}
@Test
(
expected
=
IllegalState
Exception
.
class
)
@Test
(
expected
=
UnsupportedOperation
Exception
.
class
)
public
void
headersAfterExecute
()
throws
Exception
{
ClientHttpRequest
request
=
factory
.
createRequest
(
new
URI
(
BASE_URL
+
"/echo"
),
HttpMethod
.
POST
);
request
.
getHeaders
().
add
(
"MyHeader"
,
"value"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录