Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
224bce1b
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,发现更多精彩内容 >>
提交
224bce1b
编写于
8月 15, 2011
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-8612 Allow explicit status code in HTTP 1.0 compatibility mode
上级
936c83b0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
12 deletion
+35
-12
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java
...va/org/springframework/web/servlet/view/RedirectView.java
+19
-8
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/RedirectViewTests.java
...g/springframework/web/servlet/view/RedirectViewTests.java
+16
-4
未找到文件。
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java
浏览文件 @
224bce1b
...
...
@@ -49,9 +49,9 @@ import org.springframework.web.util.WebUtils;
* <p>View that redirects to an absolute, context relative, or current request
* relative URL. The URL may be a URI template in which case the URI template
* variables will be replaced with values available in the model. By default
* all primitive model attributes (or collections thereof)
, not used as URI
*
template variables, are exposed as HTTP query parameters, but this
* behavior can be changed by overriding the
* all primitive model attributes (or collections thereof)
are exposed as HTTP
*
query parameters (assuming they've not been used as URI template variables),
* b
ut this b
ehavior can be changed by overriding the
* {@link #isEligibleProperty(String, Object)} method.
*
* <p>A URL for this view is supposed to be a HTTP redirect URL, i.e.
...
...
@@ -264,11 +264,14 @@ public class RedirectView extends AbstractUrlBasedView {
FlashMap
flashMap
=
RequestContextUtils
.
getFlashMap
(
request
);
if
(!
CollectionUtils
.
isEmpty
(
flashMap
))
{
flashMap
.
setExpectedUrl
(
request
,
targetUrl
.
toString
()).
setExpectedRequestParams
(
model
);
flashMap
.
setExpectedUrl
Path
(
request
,
targetUrl
.
toString
()
);
}
if
(
this
.
exposeModelAttributes
)
{
appendQueryProperties
(
targetUrl
,
model
,
enc
);
if
(!
CollectionUtils
.
isEmpty
(
flashMap
))
{
flashMap
.
setExpectedRequestParams
(
model
);
}
}
return
targetUrl
.
toString
();
...
...
@@ -468,14 +471,22 @@ public class RedirectView extends AbstractUrlBasedView {
HttpServletRequest
request
,
HttpServletResponse
response
,
String
targetUrl
,
boolean
http10Compatible
)
throws
IOException
{
String
encodedRedirectURL
=
response
.
encodeRedirectURL
(
targetUrl
);
if
(
http10Compatible
)
{
// Always send status code 302.
response
.
sendRedirect
(
response
.
encodeRedirectURL
(
targetUrl
));
if
(
this
.
statusCode
!=
null
)
{
response
.
setStatus
(
this
.
statusCode
.
value
());
response
.
setHeader
(
"Location"
,
encodedRedirectURL
);
}
else
{
// Send status code 302 by default.
response
.
sendRedirect
(
encodedRedirectURL
);
}
}
else
{
HttpStatus
statusCode
=
getHttp11StatusCode
(
request
,
response
,
targetUrl
);
response
.
setStatus
(
statusCode
.
value
());
response
.
setHeader
(
"Location"
,
response
.
encodeRedirectURL
(
targetUrl
)
);
response
.
setHeader
(
"Location"
,
encodedRedirectURL
);
}
}
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/RedirectViewTests.java
浏览文件 @
224bce1b
...
...
@@ -69,20 +69,32 @@ public class RedirectViewTests {
}
@Test
public
void
explicitStatusCode
()
throws
Exception
{
public
void
explicitStatusCode
Http11
()
throws
Exception
{
RedirectView
rv
=
new
RedirectView
();
rv
.
setUrl
(
"http://url.somewhere.com"
);
rv
.
setHttp10Compatible
(
false
);
rv
.
setStatusCode
(
HttpStatus
.
CREATED
);
rv
.
setStatusCode
(
HttpStatus
.
MOVED_PERMANENTLY
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
rv
.
render
(
new
HashMap
<
String
,
Object
>(),
request
,
response
);
assertEquals
(
2
01
,
response
.
getStatus
());
assertEquals
(
3
01
,
response
.
getStatus
());
assertEquals
(
"http://url.somewhere.com"
,
response
.
getHeader
(
"Location"
));
}
@Test
public
void
attributeStatusCode
()
throws
Exception
{
public
void
explicitStatusCodeHttp10
()
throws
Exception
{
RedirectView
rv
=
new
RedirectView
();
rv
.
setUrl
(
"http://url.somewhere.com"
);
rv
.
setStatusCode
(
HttpStatus
.
MOVED_PERMANENTLY
);
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
rv
.
render
(
new
HashMap
<
String
,
Object
>(),
request
,
response
);
assertEquals
(
301
,
response
.
getStatus
());
assertEquals
(
"http://url.somewhere.com"
,
response
.
getHeader
(
"Location"
));
}
@Test
public
void
attributeStatusCodeHttp11
()
throws
Exception
{
RedirectView
rv
=
new
RedirectView
();
rv
.
setUrl
(
"http://url.somewhere.com"
);
rv
.
setHttp10Compatible
(
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录