Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
e5d8fa07
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,发现更多精彩内容 >>
提交
e5d8fa07
编写于
1月 03, 2011
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-7834 - HttpHeaders.getEtag() mangles the value
上级
fbede64c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
33 addition
and
64 deletion
+33
-64
org.springframework.web/src/main/java/org/springframework/http/HttpHeaders.java
...b/src/main/java/org/springframework/http/HttpHeaders.java
+11
-32
org.springframework.web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
...pringframework/web/context/request/ServletWebRequest.java
+2
-8
org.springframework.web/src/test/java/org/springframework/http/HttpHeadersTests.java
.../test/java/org/springframework/http/HttpHeadersTests.java
+15
-6
org.springframework.web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java
...framework/web/context/request/ServletWebRequestTests.java
+5
-18
未找到文件。
org.springframework.web/src/main/java/org/springframework/http/HttpHeaders.java
浏览文件 @
e5d8fa07
/*
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -310,7 +310,11 @@ public class HttpHeaders implements MultiValueMap<String, String> {
...
@@ -310,7 +310,11 @@ public class HttpHeaders implements MultiValueMap<String, String> {
* @param eTag the new entity tag
* @param eTag the new entity tag
*/
*/
public
void
setETag
(
String
eTag
)
{
public
void
setETag
(
String
eTag
)
{
set
(
ETAG
,
quote
(
eTag
));
if
(
eTag
!=
null
)
{
Assert
.
isTrue
(
eTag
.
startsWith
(
"\""
)
||
eTag
.
startsWith
(
"W/"
),
"Invalid eTag, does not start with W/ or \""
);
Assert
.
isTrue
(
eTag
.
endsWith
(
"\""
),
"Invalid eTag, does not end with \""
);
}
set
(
ETAG
,
eTag
);
}
}
/**
/**
...
@@ -318,7 +322,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
...
@@ -318,7 +322,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
* @return the entity tag
* @return the entity tag
*/
*/
public
String
getETag
()
{
public
String
getETag
()
{
return
unquote
(
getFirst
(
ETAG
)
);
return
getFirst
(
ETAG
);
}
}
/**
/**
...
@@ -362,7 +366,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
...
@@ -362,7 +366,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
* @param ifNoneMatch the new value of the header
* @param ifNoneMatch the new value of the header
*/
*/
public
void
setIfNoneMatch
(
String
ifNoneMatch
)
{
public
void
setIfNoneMatch
(
String
ifNoneMatch
)
{
set
(
IF_NONE_MATCH
,
quote
(
ifNoneMatch
)
);
set
(
IF_NONE_MATCH
,
ifNoneMatch
);
}
}
/**
/**
...
@@ -373,7 +377,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
...
@@ -373,7 +377,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
for
(
Iterator
<
String
>
iterator
=
ifNoneMatchList
.
iterator
();
iterator
.
hasNext
();)
{
for
(
Iterator
<
String
>
iterator
=
ifNoneMatchList
.
iterator
();
iterator
.
hasNext
();)
{
String
ifNoneMatch
=
iterator
.
next
();
String
ifNoneMatch
=
iterator
.
next
();
builder
.
append
(
quote
(
ifNoneMatch
)
);
builder
.
append
(
ifNoneMatch
);
if
(
iterator
.
hasNext
())
{
if
(
iterator
.
hasNext
())
{
builder
.
append
(
", "
);
builder
.
append
(
", "
);
}
}
...
@@ -392,7 +396,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
...
@@ -392,7 +396,7 @@ public class HttpHeaders implements MultiValueMap<String, String> {
if
(
value
!=
null
)
{
if
(
value
!=
null
)
{
String
[]
tokens
=
value
.
split
(
",\\s*"
);
String
[]
tokens
=
value
.
split
(
",\\s*"
);
for
(
String
token
:
tokens
)
{
for
(
String
token
:
tokens
)
{
result
.
add
(
unquote
(
token
)
);
result
.
add
(
token
);
}
}
}
}
return
result
;
return
result
;
...
@@ -452,31 +456,6 @@ public class HttpHeaders implements MultiValueMap<String, String> {
...
@@ -452,31 +456,6 @@ public class HttpHeaders implements MultiValueMap<String, String> {
// Utility methods
// Utility methods
private
String
quote
(
String
s
)
{
Assert
.
notNull
(
s
);
if
(!
s
.
startsWith
(
"\""
))
{
s
=
"\""
+
s
;
}
if
(!
s
.
endsWith
(
"\""
))
{
s
=
s
+
"\""
;
}
return
s
;
}
private
String
unquote
(
String
s
)
{
if
(
s
==
null
)
{
return
null
;
}
if
(
s
.
startsWith
(
"\""
))
{
s
=
s
.
substring
(
1
);
}
if
(
s
.
endsWith
(
"\""
))
{
s
=
s
.
substring
(
0
,
s
.
length
()
-
1
);
}
return
s
;
}
private
long
getFirstDate
(
String
headerName
)
{
private
long
getFirstDate
(
String
headerName
)
{
String
headerValue
=
getFirst
(
headerName
);
String
headerValue
=
getFirst
(
headerName
);
if
(
headerValue
==
null
)
{
if
(
headerValue
==
null
)
{
...
...
org.springframework.web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
浏览文件 @
e5d8fa07
/*
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -206,12 +206,6 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
...
@@ -206,12 +206,6 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
public
boolean
checkNotModified
(
String
eTag
)
{
public
boolean
checkNotModified
(
String
eTag
)
{
if
(
StringUtils
.
hasLength
(
eTag
)
&&
!
this
.
notModified
&&
if
(
StringUtils
.
hasLength
(
eTag
)
&&
!
this
.
notModified
&&
(
this
.
response
==
null
||
!
this
.
response
.
containsHeader
(
HEADER_ETAG
)))
{
(
this
.
response
==
null
||
!
this
.
response
.
containsHeader
(
HEADER_ETAG
)))
{
if
(!
eTag
.
startsWith
(
"\""
))
{
eTag
=
"\""
+
eTag
;
}
if
(!
eTag
.
endsWith
(
"\""
))
{
eTag
=
eTag
+
"\""
;
}
String
ifNoneMatch
=
getRequest
().
getHeader
(
HEADER_IF_NONE_MATCH
);
String
ifNoneMatch
=
getRequest
().
getHeader
(
HEADER_IF_NONE_MATCH
);
this
.
notModified
=
eTag
.
equals
(
ifNoneMatch
);
this
.
notModified
=
eTag
.
equals
(
ifNoneMatch
);
if
(
this
.
response
!=
null
)
{
if
(
this
.
response
!=
null
)
{
...
...
org.springframework.web/src/test/java/org/springframework/http/HttpHeadersTests.java
浏览文件 @
e5d8fa07
/*
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -27,10 +27,11 @@ import java.util.List;
...
@@ -27,10 +27,11 @@ import java.util.List;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/** @author Arjen Poutsma */
/** @author Arjen Poutsma */
public
class
HttpHeadersTests
{
public
class
HttpHeadersTests
{
...
@@ -99,6 +100,14 @@ public class HttpHeadersTests {
...
@@ -99,6 +100,14 @@ public class HttpHeadersTests {
@Test
@Test
public
void
eTag
()
{
public
void
eTag
()
{
String
eTag
=
"\"v2.6\""
;
headers
.
setETag
(
eTag
);
assertEquals
(
"Invalid ETag header"
,
eTag
,
headers
.
getETag
());
assertEquals
(
"Invalid ETag header"
,
"\"v2.6\""
,
headers
.
getFirst
(
"ETag"
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
illegalETag
()
{
String
eTag
=
"v2.6"
;
String
eTag
=
"v2.6"
;
headers
.
setETag
(
eTag
);
headers
.
setETag
(
eTag
);
assertEquals
(
"Invalid ETag header"
,
eTag
,
headers
.
getETag
());
assertEquals
(
"Invalid ETag header"
,
eTag
,
headers
.
getETag
());
...
@@ -107,7 +116,7 @@ public class HttpHeadersTests {
...
@@ -107,7 +116,7 @@ public class HttpHeadersTests {
@Test
@Test
public
void
ifNoneMatch
()
{
public
void
ifNoneMatch
()
{
String
ifNoneMatch
=
"
v2.6
"
;
String
ifNoneMatch
=
"
\"v2.6\"
"
;
headers
.
setIfNoneMatch
(
ifNoneMatch
);
headers
.
setIfNoneMatch
(
ifNoneMatch
);
assertEquals
(
"Invalid If-None-Match header"
,
ifNoneMatch
,
headers
.
getIfNoneMatch
().
get
(
0
));
assertEquals
(
"Invalid If-None-Match header"
,
ifNoneMatch
,
headers
.
getIfNoneMatch
().
get
(
0
));
assertEquals
(
"Invalid If-None-Match header"
,
"\"v2.6\""
,
headers
.
getFirst
(
"If-None-Match"
));
assertEquals
(
"Invalid If-None-Match header"
,
"\"v2.6\""
,
headers
.
getFirst
(
"If-None-Match"
));
...
@@ -115,8 +124,8 @@ public class HttpHeadersTests {
...
@@ -115,8 +124,8 @@ public class HttpHeadersTests {
@Test
@Test
public
void
ifNoneMatchList
()
{
public
void
ifNoneMatchList
()
{
String
ifNoneMatch1
=
"
v2.6
"
;
String
ifNoneMatch1
=
"
\"v2.6\"
"
;
String
ifNoneMatch2
=
"
v2.7
"
;
String
ifNoneMatch2
=
"
\"v2.7\"
"
;
List
<
String
>
ifNoneMatchList
=
new
ArrayList
<
String
>(
2
);
List
<
String
>
ifNoneMatchList
=
new
ArrayList
<
String
>(
2
);
ifNoneMatchList
.
add
(
ifNoneMatch1
);
ifNoneMatchList
.
add
(
ifNoneMatch1
);
ifNoneMatchList
.
add
(
ifNoneMatch2
);
ifNoneMatchList
.
add
(
ifNoneMatch2
);
...
...
org.springframework.web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java
浏览文件 @
e5d8fa07
/*
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
1
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -141,9 +141,9 @@ public class ServletWebRequestTests {
...
@@ -141,9 +141,9 @@ public class ServletWebRequestTests {
@Test
@Test
public
void
checkNotModifiedETag
()
{
public
void
checkNotModifiedETag
()
{
String
eTag
=
"
Foo
"
;
String
eTag
=
"
\"Foo\"
"
;
servletRequest
.
setMethod
(
"GET"
);
servletRequest
.
setMethod
(
"GET"
);
servletRequest
.
addHeader
(
"If-None-Match"
,
"\""
+
eTag
+
"\""
);
servletRequest
.
addHeader
(
"If-None-Match"
,
eTag
);
request
.
checkNotModified
(
eTag
);
request
.
checkNotModified
(
eTag
);
...
@@ -151,20 +151,7 @@ public class ServletWebRequestTests {
...
@@ -151,20 +151,7 @@ public class ServletWebRequestTests {
}
}
@Test
@Test
public
void
checkModifiedETagNonQuoted
()
{
public
void
checkModifiedETag
()
{
String
currentETag
=
"Foo"
;
String
oldEtag
=
"Bar"
;
servletRequest
.
setMethod
(
"GET"
);
servletRequest
.
addHeader
(
"If-None-Match"
,
"\""
+
oldEtag
+
"\""
);
request
.
checkNotModified
(
currentETag
);
assertEquals
(
200
,
servletResponse
.
getStatus
());
assertEquals
(
"\""
+
currentETag
+
"\""
,
servletResponse
.
getHeader
(
"ETag"
));
}
@Test
public
void
checkModifiedETagQuoted
()
{
String
currentETag
=
"\"Foo\""
;
String
currentETag
=
"\"Foo\""
;
String
oldEtag
=
"Bar"
;
String
oldEtag
=
"Bar"
;
servletRequest
.
setMethod
(
"GET"
);
servletRequest
.
setMethod
(
"GET"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录