Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
4e10735e
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 搜索 >>
提交
4e10735e
编写于
5月 03, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MockHttpServletRequest restores default locale for empty accept header
Closes gh-22877
上级
7aa61d9e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
19 deletion
+30
-19
spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java
.../org/springframework/mock/web/MockHttpServletRequest.java
+11
-9
spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java
...springframework/mock/web/MockHttpServletRequestTests.java
+8
-1
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
...springframework/mock/web/test/MockHttpServletRequest.java
+11
-9
未找到文件。
spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java
浏览文件 @
4e10735e
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -199,7 +199,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private
String
remoteHost
=
DEFAULT_REMOTE_HOST
;
/** List of locales in descending order. */
private
final
List
<
Locale
>
locales
=
new
LinkedList
<>();
private
final
Li
nkedLi
st
<
Locale
>
locales
=
new
LinkedList
<>();
private
boolean
secure
=
false
;
...
...
@@ -403,12 +403,11 @@ public class MockHttpServletRequest implements HttpServletRequest {
private
void
updateContentTypeHeader
()
{
if
(
StringUtils
.
hasLength
(
this
.
contentType
))
{
StringBuilder
sb
=
new
StringBuilder
(
this
.
contentType
);
if
(!
this
.
contentType
.
toLowerCase
().
contains
(
CHARSET_PREFIX
)
&&
StringUtils
.
hasLength
(
this
.
characterEncoding
))
{
sb
.
append
(
";"
).
append
(
CHARSET_PREFIX
).
append
(
this
.
characterEncoding
);
String
value
=
this
.
contentType
;
if
(
StringUtils
.
hasLength
(
this
.
characterEncoding
)
&&
!
this
.
contentType
.
toLowerCase
().
contains
(
CHARSET_PREFIX
))
{
value
+=
';'
+
CHARSET_PREFIX
+
this
.
characterEncoding
;
}
doAddHeaderValue
(
HttpHeaders
.
CONTENT_TYPE
,
sb
.
toString
()
,
true
);
doAddHeaderValue
(
HttpHeaders
.
CONTENT_TYPE
,
value
,
true
);
}
}
...
...
@@ -780,7 +779,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public
void
addPreferredLocale
(
Locale
locale
)
{
Assert
.
notNull
(
locale
,
"Locale must not be null"
);
this
.
locales
.
add
(
0
,
locale
);
this
.
locales
.
add
First
(
locale
);
updateAcceptLanguageHeader
();
}
...
...
@@ -818,7 +817,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
@Override
public
Locale
getLocale
()
{
return
this
.
locales
.
get
(
0
);
return
this
.
locales
.
get
First
(
);
}
/**
...
...
@@ -1016,6 +1015,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
List
<
Locale
>
locales
=
headers
.
getAcceptLanguageAsLocales
();
this
.
locales
.
clear
();
this
.
locales
.
addAll
(
locales
);
if
(
this
.
locales
.
isEmpty
())
{
this
.
locales
.
add
(
Locale
.
ENGLISH
);
}
}
catch
(
IllegalArgumentException
ex
)
{
// Invalid Accept-Language format -> just store plain header
...
...
spring-test/src/test/java/org/springframework/mock/web/MockHttpServletRequestTests.java
浏览文件 @
4e10735e
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -351,6 +351,13 @@ public class MockHttpServletRequestTests {
assertEquals
(
"en_US"
,
request
.
getHeader
(
"Accept-Language"
));
}
@Test
public
void
emptyAcceptLanguageHeader
()
{
request
.
addHeader
(
"Accept-Language"
,
""
);
assertEquals
(
Locale
.
ENGLISH
,
request
.
getLocale
());
assertEquals
(
""
,
request
.
getHeader
(
"Accept-Language"
));
}
@Test
public
void
getServerNameWithDefaultName
()
{
assertEquals
(
"localhost"
,
request
.
getServerName
());
...
...
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
浏览文件 @
4e10735e
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -199,7 +199,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
private
String
remoteHost
=
DEFAULT_REMOTE_HOST
;
/** List of locales in descending order. */
private
final
List
<
Locale
>
locales
=
new
LinkedList
<>();
private
final
Li
nkedLi
st
<
Locale
>
locales
=
new
LinkedList
<>();
private
boolean
secure
=
false
;
...
...
@@ -403,12 +403,11 @@ public class MockHttpServletRequest implements HttpServletRequest {
private
void
updateContentTypeHeader
()
{
if
(
StringUtils
.
hasLength
(
this
.
contentType
))
{
StringBuilder
sb
=
new
StringBuilder
(
this
.
contentType
);
if
(!
this
.
contentType
.
toLowerCase
().
contains
(
CHARSET_PREFIX
)
&&
StringUtils
.
hasLength
(
this
.
characterEncoding
))
{
sb
.
append
(
";"
).
append
(
CHARSET_PREFIX
).
append
(
this
.
characterEncoding
);
String
value
=
this
.
contentType
;
if
(
StringUtils
.
hasLength
(
this
.
characterEncoding
)
&&
!
this
.
contentType
.
toLowerCase
().
contains
(
CHARSET_PREFIX
))
{
value
+=
';'
+
CHARSET_PREFIX
+
this
.
characterEncoding
;
}
doAddHeaderValue
(
HttpHeaders
.
CONTENT_TYPE
,
sb
.
toString
()
,
true
);
doAddHeaderValue
(
HttpHeaders
.
CONTENT_TYPE
,
value
,
true
);
}
}
...
...
@@ -780,7 +779,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public
void
addPreferredLocale
(
Locale
locale
)
{
Assert
.
notNull
(
locale
,
"Locale must not be null"
);
this
.
locales
.
add
(
0
,
locale
);
this
.
locales
.
add
First
(
locale
);
updateAcceptLanguageHeader
();
}
...
...
@@ -818,7 +817,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
@Override
public
Locale
getLocale
()
{
return
this
.
locales
.
get
(
0
);
return
this
.
locales
.
get
First
(
);
}
/**
...
...
@@ -1016,6 +1015,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
List
<
Locale
>
locales
=
headers
.
getAcceptLanguageAsLocales
();
this
.
locales
.
clear
();
this
.
locales
.
addAll
(
locales
);
if
(
this
.
locales
.
isEmpty
())
{
this
.
locales
.
add
(
Locale
.
ENGLISH
);
}
}
catch
(
IllegalArgumentException
ex
)
{
// Invalid Accept-Language format -> just store plain header
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录