Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
4261f34b
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
4261f34b
编写于
12月 09, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent and lenient HttpMethod resolution across all web modules
Issue: SPR-13776
上级
34b596c6
变更
29
隐藏空白更改
内联
并排
Showing
29 changed file
with
149 addition
and
109 deletion
+149
-109
spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java
...ngframework/mock/web/MockMultipartHttpServletRequest.java
+2
-2
spring-web/src/main/java/org/springframework/http/HttpHeaders.java
...b/src/main/java/org/springframework/http/HttpHeaders.java
+18
-13
spring-web/src/main/java/org/springframework/http/HttpMethod.java
...eb/src/main/java/org/springframework/http/HttpMethod.java
+38
-2
spring-web/src/main/java/org/springframework/http/HttpRequest.java
...b/src/main/java/org/springframework/http/HttpRequest.java
+6
-5
spring-web/src/main/java/org/springframework/http/RequestEntity.java
...src/main/java/org/springframework/http/RequestEntity.java
+0
-3
spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java
...ork/http/client/HttpComponentsAsyncClientHttpRequest.java
+1
-1
spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java
...ramework/http/client/HttpComponentsClientHttpRequest.java
+1
-1
spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java
...http/client/HttpComponentsStreamingClientHttpRequest.java
+1
-1
spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java
...rk/http/client/SimpleBufferingAsyncClientHttpRequest.java
+4
-4
spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java
...amework/http/client/SimpleBufferingClientHttpRequest.java
+3
-3
spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java
...rk/http/client/SimpleStreamingAsyncClientHttpRequest.java
+2
-2
spring-web/src/main/java/org/springframework/http/client/SimpleStreamingClientHttpRequest.java
...amework/http/client/SimpleStreamingClientHttpRequest.java
+2
-2
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java
...springframework/http/server/ServletServerHttpRequest.java
+19
-18
spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java
...framework/web/HttpRequestMethodNotSupportedException.java
+10
-6
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMethod.java
...rg/springframework/web/bind/annotation/RequestMethod.java
+6
-8
spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
...pringframework/web/context/request/ServletWebRequest.java
+1
-1
spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java
.../java/org/springframework/web/cors/CorsConfiguration.java
+5
-2
spring-web/src/main/java/org/springframework/web/cors/CorsUtils.java
...src/main/java/org/springframework/web/cors/CorsUtils.java
+2
-2
spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java
...g/springframework/web/filter/ShallowEtagHeaderFilter.java
+1
-1
spring-web/src/main/java/org/springframework/web/multipart/support/AbstractMultipartHttpServletRequest.java
...ultipart/support/AbstractMultipartHttpServletRequest.java
+2
-2
spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java
...pringframework/web/util/ContentCachingRequestWrapper.java
+3
-3
spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java
...mework/mock/web/test/MockMultipartHttpServletRequest.java
+2
-2
spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java
...va/org/springframework/web/servlet/DispatcherServlet.java
+2
-3
spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java
...ava/org/springframework/web/servlet/FrameworkServlet.java
+3
-4
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java
...ation/AbstractMessageConverterMethodArgumentResolver.java
+5
-5
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java
...vlet/mvc/method/annotation/HttpEntityMethodProcessor.java
+3
-6
spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java
...k/web/socket/server/support/AbstractHandshakeHandler.java
+3
-3
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java
...work/web/socket/sockjs/support/AbstractSockJsService.java
+2
-2
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java
...cket/sockjs/transport/TransportHandlingSockJsService.java
+2
-2
未找到文件。
spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -128,7 +128,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
@Override
public
HttpMethod
getRequestMethod
()
{
return
HttpMethod
.
valueOf
(
getMethod
());
return
HttpMethod
.
resolve
(
getMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/http/HttpHeaders.java
浏览文件 @
4261f34b
...
...
@@ -470,7 +470,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Access-Control-Allow-Methods} response header.
* Return the value of the {@code Access-Control-Allow-Methods} response header.
*/
public
List
<
HttpMethod
>
getAccessControlAllowMethods
()
{
List
<
HttpMethod
>
result
=
new
ArrayList
<
HttpMethod
>();
...
...
@@ -478,7 +478,10 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
if
(
value
!=
null
)
{
String
[]
tokens
=
value
.
split
(
",\\s*"
);
for
(
String
token
:
tokens
)
{
result
.
add
(
HttpMethod
.
valueOf
(
token
));
HttpMethod
resolved
=
HttpMethod
.
resolve
(
token
);
if
(
resolved
!=
null
)
{
result
.
add
(
resolved
);
}
}
}
return
result
;
...
...
@@ -492,7 +495,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Access-Control-Allow-Origin} response header.
* Return the value of the {@code Access-Control-Allow-Origin} response header.
*/
public
String
getAccessControlAllowOrigin
()
{
return
getFirst
(
ACCESS_CONTROL_ALLOW_ORIGIN
);
...
...
@@ -550,11 +553,10 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Access-Control-Request-Method} request header.
* Return the value of the {@code Access-Control-Request-Method} request header.
*/
public
HttpMethod
getAccessControlRequestMethod
()
{
String
value
=
getFirst
(
ACCESS_CONTROL_REQUEST_METHOD
);
return
(
value
!=
null
?
HttpMethod
.
valueOf
(
value
)
:
null
);
return
HttpMethod
.
resolve
(
getFirst
(
ACCESS_CONTROL_REQUEST_METHOD
));
}
/**
...
...
@@ -615,12 +617,15 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
public
Set
<
HttpMethod
>
getAllow
()
{
String
value
=
getFirst
(
ALLOW
);
if
(!
StringUtils
.
isEmpty
(
value
))
{
List
<
HttpMethod
>
allowedMethod
=
new
ArrayList
<
HttpMethod
>(
5
);
List
<
HttpMethod
>
result
=
new
LinkedList
<
HttpMethod
>(
);
String
[]
tokens
=
value
.
split
(
",\\s*"
);
for
(
String
token
:
tokens
)
{
allowedMethod
.
add
(
HttpMethod
.
valueOf
(
token
));
HttpMethod
resolved
=
HttpMethod
.
resolve
(
token
);
if
(
resolved
!=
null
)
{
result
.
add
(
resolved
);
}
}
return
EnumSet
.
copyOf
(
allowedMethod
);
return
EnumSet
.
copyOf
(
result
);
}
else
{
return
EnumSet
.
noneOf
(
HttpMethod
.
class
);
...
...
@@ -635,7 +640,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Cache-Control} header.
* Return the value of the {@code Cache-Control} header.
*/
public
String
getCacheControl
()
{
return
getFirst
(
CACHE_CONTROL
);
...
...
@@ -656,7 +661,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Connection} header.
* Return the value of the {@code Connection} header.
*/
public
List
<
String
>
getConnection
()
{
return
getFirstValueAsList
(
CONNECTION
);
...
...
@@ -920,7 +925,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Range} header.
* Return the value of the {@code Range} header.
* <p>Returns an empty list when the range is unknown.
*/
public
List
<
HttpRange
>
getRange
()
{
...
...
@@ -936,7 +941,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
}
/**
* Return
s
the value of the {@code Upgrade} header.
* Return the value of the {@code Upgrade} header.
*/
public
String
getUpgrade
()
{
return
getFirst
(
UPGRADE
);
...
...
spring-web/src/main/java/org/springframework/http/HttpMethod.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -16,16 +16,52 @@
package
org.springframework.http
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Java 5 enumeration of HTTP request methods. Intended for use
* with {@link org.springframework.http.client.ClientHttpRequest}
* and {@link org.springframework.web.client.RestTemplate}.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.0
*/
public
enum
HttpMethod
{
GET
,
POST
,
HEAD
,
OPTIONS
,
PUT
,
PATCH
,
DELETE
,
TRACE
GET
,
HEAD
,
POST
,
PUT
,
PATCH
,
DELETE
,
OPTIONS
,
TRACE
;
private
static
final
Map
<
String
,
HttpMethod
>
mappings
=
new
HashMap
<
String
,
HttpMethod
>(
8
);
static
{
for
(
HttpMethod
httpMethod
:
values
())
{
mappings
.
put
(
httpMethod
.
name
(),
httpMethod
);
}
}
/**
* Resolve the given method value to an {@code HttpMethod}.
* @param method the method value as a String
* @return the corresponding {@code HttpMethod}, or {@code null} if not found
* @since 4.2.4
*/
public
static
HttpMethod
resolve
(
String
method
)
{
return
(
method
!=
null
?
mappings
.
get
(
method
)
:
null
);
}
/**
* Determine whether this {@code HttpMethod} matches the given
* method value.
* @param method the method value as a String
* @return {@code true} if it matches, {@code false} otherwise
* @since 4.2.4
*/
public
boolean
matches
(
String
method
)
{
return
name
().
equals
(
method
);
}
}
spring-web/src/main/java/org/springframework/http/HttpRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -19,8 +19,8 @@ package org.springframework.http;
import
java.net.URI
;
/**
* Represents an HTTP request message, consisting of
{@linkplain #getMethod() method}
* and {@linkplain #getURI() uri}.
* Represents an HTTP request message, consisting of
*
{@linkplain #getMethod() method}
and {@linkplain #getURI() uri}.
*
* @author Arjen Poutsma
* @since 3.1
...
...
@@ -29,13 +29,14 @@ public interface HttpRequest extends HttpMessage {
/**
* Return the HTTP method of the request.
* @return the HTTP method as an HttpMethod enum value
* @return the HTTP method as an HttpMethod enum value, or {@code null}
* if not resolvable (e.g. in case of a non-standard HTTP method)
*/
HttpMethod
getMethod
();
/**
* Return the URI of the request.
* @return the URI of the request
* @return the URI of the request
(never {@code null})
*/
URI
getURI
();
...
...
spring-web/src/main/java/org/springframework/http/RequestEntity.java
浏览文件 @
4261f34b
...
...
@@ -20,7 +20,6 @@ import java.net.URI;
import
java.nio.charset.Charset
;
import
java.util.Arrays
;
import
org.springframework.util.Assert
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -104,8 +103,6 @@ public class RequestEntity<T> extends HttpEntity<T> {
*/
public
RequestEntity
(
T
body
,
MultiValueMap
<
String
,
String
>
headers
,
HttpMethod
method
,
URI
url
)
{
super
(
body
,
headers
);
Assert
.
notNull
(
method
,
"'method' is required"
);
Assert
.
notNull
(
url
,
"'url' is required"
);
this
.
method
=
method
;
this
.
url
=
url
;
}
...
...
spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java
浏览文件 @
4261f34b
...
...
@@ -68,7 +68,7 @@ final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncC
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
httpRequest
.
getMethod
());
return
HttpMethod
.
resolve
(
this
.
httpRequest
.
getMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java
浏览文件 @
4261f34b
...
...
@@ -66,7 +66,7 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
httpRequest
.
getMethod
());
return
HttpMethod
.
resolve
(
this
.
httpRequest
.
getMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java
浏览文件 @
4261f34b
...
...
@@ -65,7 +65,7 @@ final class HttpComponentsStreamingClientHttpRequest extends AbstractClientHttpR
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
httpRequest
.
getMethod
());
return
HttpMethod
.
resolve
(
this
.
httpRequest
.
getMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -57,7 +57,7 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
connection
.
getRequestMethod
());
return
HttpMethod
.
resolve
(
this
.
connection
.
getRequestMethod
());
}
@Override
...
...
@@ -78,8 +78,8 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
@Override
public
ClientHttpResponse
call
()
throws
Exception
{
SimpleBufferingClientHttpRequest
.
addHeaders
(
connection
,
headers
);
// JDK <
1.8 doesn't support getOutputStream with HTTP DELETE
if
(
HttpMethod
.
DELETE
.
equals
(
getMethod
()
)
&&
bufferedOutput
.
length
==
0
)
{
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
if
(
HttpMethod
.
DELETE
==
getMethod
(
)
&&
bufferedOutput
.
length
==
0
)
{
connection
.
setDoOutput
(
false
);
}
if
(
connection
.
getDoOutput
()
&&
outputStreaming
)
{
...
...
spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java
浏览文件 @
4261f34b
...
...
@@ -52,7 +52,7 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
connection
.
getRequestMethod
());
return
HttpMethod
.
resolve
(
this
.
connection
.
getRequestMethod
());
}
@Override
...
...
@@ -69,8 +69,8 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
protected
ClientHttpResponse
executeInternal
(
HttpHeaders
headers
,
byte
[]
bufferedOutput
)
throws
IOException
{
addHeaders
(
this
.
connection
,
headers
);
// JDK <
1.8 doesn't support getOutputStream with HTTP DELETE
if
(
HttpMethod
.
DELETE
.
equals
(
getMethod
()
)
&&
bufferedOutput
.
length
==
0
)
{
// JDK <1.8 doesn't support getOutputStream with HTTP DELETE
if
(
HttpMethod
.
DELETE
==
getMethod
(
)
&&
bufferedOutput
.
length
==
0
)
{
this
.
connection
.
setDoOutput
(
false
);
}
...
...
spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -63,7 +63,7 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
connection
.
getRequestMethod
());
return
HttpMethod
.
resolve
(
this
.
connection
.
getRequestMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/http/client/SimpleStreamingClientHttpRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -53,7 +53,7 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
connection
.
getRequestMethod
());
return
HttpMethod
.
resolve
(
this
.
connection
.
getRequestMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -55,8 +55,6 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
protected
static
final
String
FORM_CHARSET
=
"UTF-8"
;
private
static
final
String
METHOD_POST
=
"POST"
;
private
final
HttpServletRequest
servletRequest
;
...
...
@@ -84,7 +82,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
@Override
public
HttpMethod
getMethod
()
{
return
HttpMethod
.
valueOf
(
this
.
servletRequest
.
getMethod
());
return
HttpMethod
.
resolve
(
this
.
servletRequest
.
getMethod
());
}
@Override
...
...
@@ -166,9 +164,22 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
}
}
private
boolean
isFormPost
(
HttpServletRequest
request
)
{
return
(
request
.
getContentType
()
!=
null
&&
request
.
getContentType
().
contains
(
FORM_CONTENT_TYPE
)
&&
METHOD_POST
.
equalsIgnoreCase
(
request
.
getMethod
()));
@Override
public
ServerHttpAsyncRequestControl
getAsyncRequestControl
(
ServerHttpResponse
response
)
{
if
(
this
.
asyncRequestControl
==
null
)
{
Assert
.
isInstanceOf
(
ServletServerHttpResponse
.
class
,
response
);
ServletServerHttpResponse
servletServerResponse
=
(
ServletServerHttpResponse
)
response
;
this
.
asyncRequestControl
=
new
ServletServerHttpAsyncRequestControl
(
this
,
servletServerResponse
);
}
return
this
.
asyncRequestControl
;
}
private
static
boolean
isFormPost
(
HttpServletRequest
request
)
{
String
contentType
=
request
.
getContentType
();
return
(
contentType
!=
null
&&
contentType
.
contains
(
FORM_CONTENT_TYPE
)
&&
HttpMethod
.
POST
.
matches
(
request
.
getMethod
()));
}
/**
...
...
@@ -177,7 +188,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
* from the body, which can fail if any other code has used ServletRequest
* to access a parameter thus causing the input stream to be "consumed".
*/
private
InputStream
getBodyFromServletRequestParameters
(
HttpServletRequest
request
)
throws
IOException
{
private
static
InputStream
getBodyFromServletRequestParameters
(
HttpServletRequest
request
)
throws
IOException
{
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
(
1024
);
Writer
writer
=
new
OutputStreamWriter
(
bos
,
FORM_CHARSET
);
...
...
@@ -205,14 +216,4 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
return
new
ByteArrayInputStream
(
bos
.
toByteArray
());
}
@Override
public
ServerHttpAsyncRequestControl
getAsyncRequestControl
(
ServerHttpResponse
response
)
{
if
(
this
.
asyncRequestControl
==
null
)
{
Assert
.
isInstanceOf
(
ServletServerHttpResponse
.
class
,
response
);
ServletServerHttpResponse
servletServerResponse
=
(
ServletServerHttpResponse
)
response
;
this
.
asyncRequestControl
=
new
ServletServerHttpAsyncRequestControl
(
this
,
servletServerResponse
);
}
return
this
.
asyncRequestControl
;
}
}
spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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,8 +17,9 @@
package
org.springframework.web
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.EnumSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Set
;
import
javax.servlet.ServletException
;
...
...
@@ -105,11 +106,14 @@ public class HttpRequestMethodNotSupportedException extends ServletException {
* Return the actually supported HTTP methods, if known, as {@link HttpMethod} instances.
*/
public
Set
<
HttpMethod
>
getSupportedHttpMethods
()
{
Set
<
HttpMethod
>
supportedMethods
=
new
LinkedHashSe
t
<
HttpMethod
>();
List
<
HttpMethod
>
supportedMethods
=
new
LinkedLis
t
<
HttpMethod
>();
for
(
String
value
:
this
.
supportedMethods
)
{
supportedMethods
.
add
(
HttpMethod
.
valueOf
(
value
));
HttpMethod
resolved
=
HttpMethod
.
resolve
(
value
);
if
(
resolved
!=
null
)
{
supportedMethods
.
add
(
resolved
);
}
}
return
Collections
.
unmodifiableSet
(
supportedMethods
);
return
EnumSet
.
copyOf
(
supportedMethods
);
}
}
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMethod.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
5
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,16 +17,14 @@
package
org.springframework.web.bind.annotation
;
/**
* Java 5 enumeration of HTTP request methods. Intended for use
* with the {@link RequestMapping#method()} attribute of the
* {@link RequestMapping} annotation.
* Java 5 enumeration of HTTP request methods. Intended for use with the
* {@link RequestMapping#method()} attribute of the {@link RequestMapping} annotation.
*
* <p>Note that, by default, {@link org.springframework.web.servlet.DispatcherServlet}
* supports GET, HEAD, POST, PUT, PATCH and DELETE only. DispatcherServlet will
* process TRACE and OPTIONS with the default HttpServlet behavior unless
* explicitly told to dispatch those request types as well: Check out
* the "dispatchOptionsRequest" and "dispatchTraceRequest" properties,
* switching them to "true" if necessary.
* process TRACE and OPTIONS with the default HttpServlet behavior unless explicitly
* told to dispatch those request types as well: Check out the "dispatchOptionsRequest"
* and "dispatchTraceRequest" properties, switching them to "true" if necessary.
*
* @author Juergen Hoeller
* @since 2.5
...
...
spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
浏览文件 @
4261f34b
...
...
@@ -106,7 +106,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
* @since 4.0.2
*/
public
HttpMethod
getHttpMethod
()
{
return
HttpMethod
.
valueOf
(
getRequest
().
getMethod
());
return
HttpMethod
.
resolve
(
getRequest
().
getMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java
浏览文件 @
4261f34b
...
...
@@ -344,10 +344,13 @@ public class CorsConfiguration {
List
<
HttpMethod
>
result
=
new
ArrayList
<
HttpMethod
>(
allowedMethods
.
size
());
boolean
allowed
=
false
;
for
(
String
method
:
allowedMethods
)
{
if
(
requestMethod
.
name
().
equal
s
(
method
))
{
if
(
requestMethod
.
matche
s
(
method
))
{
allowed
=
true
;
}
result
.
add
(
HttpMethod
.
valueOf
(
method
));
HttpMethod
resolved
=
HttpMethod
.
resolve
(
method
);
if
(
resolved
!=
null
)
{
result
.
add
(
resolved
);
}
}
return
(
allowed
?
result
:
null
);
}
...
...
spring-web/src/main/java/org/springframework/web/cors/CorsUtils.java
浏览文件 @
4261f34b
...
...
@@ -28,7 +28,7 @@ import org.springframework.http.HttpMethod;
* @author Sebastien Deleuze
* @since 4.2
*/
public
class
CorsUtils
{
public
abstract
class
CorsUtils
{
/**
* Returns {@code true} if the request is a valid CORS one.
...
...
@@ -41,7 +41,7 @@ public class CorsUtils {
* Returns {@code true} if the request is a valid CORS pre-flight one.
*/
public
static
boolean
isPreFlightRequest
(
HttpServletRequest
request
)
{
return
(
isCorsRequest
(
request
)
&&
request
.
getMethod
().
equals
(
HttpMethod
.
OPTIONS
.
name
())
&&
return
(
isCorsRequest
(
request
)
&&
HttpMethod
.
OPTIONS
.
matches
(
request
.
getMethod
())
&&
request
.
getHeader
(
HttpHeaders
.
ACCESS_CONTROL_REQUEST_METHOD
)
!=
null
);
}
...
...
spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java
浏览文件 @
4261f34b
...
...
@@ -144,7 +144,7 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
protected
boolean
isEligibleForEtag
(
HttpServletRequest
request
,
HttpServletResponse
response
,
int
responseStatusCode
,
InputStream
inputStream
)
{
if
(
responseStatusCode
>=
200
&&
responseStatusCode
<
300
&&
HttpMethod
.
GET
.
name
().
equal
s
(
request
.
getMethod
()))
{
if
(
responseStatusCode
>=
200
&&
responseStatusCode
<
300
&&
HttpMethod
.
GET
.
matche
s
(
request
.
getMethod
()))
{
String
cacheControl
=
null
;
if
(
servlet3Present
)
{
cacheControl
=
response
.
getHeader
(
HEADER_CACHE_CONTROL
);
...
...
spring-web/src/main/java/org/springframework/web/multipart/support/AbstractMultipartHttpServletRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -61,7 +61,7 @@ public abstract class AbstractMultipartHttpServletRequest extends HttpServletReq
@Override
public
HttpMethod
getRequestMethod
()
{
return
HttpMethod
.
valueOf
(
getRequest
().
getMethod
());
return
HttpMethod
.
resolve
(
getRequest
().
getMethod
());
}
@Override
...
...
spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java
浏览文件 @
4261f34b
...
...
@@ -30,6 +30,8 @@ import javax.servlet.ServletInputStream;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
org.springframework.http.HttpMethod
;
/**
* {@link javax.servlet.http.HttpServletRequest} wrapper that caches all content read from
* the {@linkplain #getInputStream() input stream} and {@linkplain #getReader() reader},
...
...
@@ -46,8 +48,6 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
private
static
final
String
FORM_CONTENT_TYPE
=
"application/x-www-form-urlencoded"
;
private
static
final
String
METHOD_POST
=
"POST"
;
private
final
ByteArrayOutputStream
cachedContent
;
...
...
@@ -125,7 +125,7 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
private
boolean
isFormPost
()
{
String
contentType
=
getContentType
();
return
(
contentType
!=
null
&&
contentType
.
contains
(
FORM_CONTENT_TYPE
)
&&
METHOD_POST
.
equalsIgnoreCase
(
getMethod
()));
HttpMethod
.
POST
.
matches
(
getMethod
()));
}
private
void
writeRequestParametersToCachedContent
()
{
...
...
spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java
浏览文件 @
4261f34b
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -128,7 +128,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl
@Override
public
HttpMethod
getRequestMethod
()
{
return
HttpMethod
.
valueOf
(
getMethod
());
return
HttpMethod
.
resolve
(
getMethod
());
}
@Override
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java
浏览文件 @
4261f34b
...
...
@@ -1137,9 +1137,8 @@ public class DispatcherServlet extends FrameworkServlet {
"] in DispatcherServlet with name '"
+
getServletName
()
+
"'"
);
}
if
(
this
.
throwExceptionIfNoHandlerFound
)
{
ServletServerHttpRequest
sshr
=
new
ServletServerHttpRequest
(
request
);
throw
new
NoHandlerFoundException
(
sshr
.
getMethod
().
name
(),
sshr
.
getServletRequest
().
getRequestURI
(),
sshr
.
getHeaders
());
throw
new
NoHandlerFoundException
(
request
.
getMethod
(),
getRequestUri
(
request
),
new
ServletServerHttpRequest
(
request
).
getHeaders
());
}
else
{
response
.
sendError
(
HttpServletResponse
.
SC_NOT_FOUND
);
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java
浏览文件 @
4261f34b
...
...
@@ -42,6 +42,7 @@ import org.springframework.context.i18n.SimpleLocaleContext;
import
org.springframework.core.GenericTypeResolver
;
import
org.springframework.core.annotation.AnnotationAwareOrderComparator
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -831,15 +832,13 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
/**
* Override the parent class implementation in order to intercept PATCH
* requests.
* Override the parent class implementation in order to intercept PATCH requests.
*/
@Override
protected
void
service
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
method
=
request
.
getMethod
();
if
(
method
.
equalsIgnoreCase
(
RequestMethod
.
PATCH
.
name
()))
{
if
(
HttpMethod
.
PATCH
.
matches
(
request
.
getMethod
()))
{
processRequest
(
request
,
response
);
}
else
{
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java
浏览文件 @
4261f34b
...
...
@@ -22,8 +22,8 @@ import java.io.PushbackInputStream;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.EnumSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -63,8 +63,8 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
*/
public
abstract
class
AbstractMessageConverterMethodArgumentResolver
implements
HandlerMethodArgumentResolver
{
private
static
final
Lis
t
<
HttpMethod
>
SUPPORTED_METHODS
=
Arrays
.
asList
(
HttpMethod
.
POST
,
HttpMethod
.
PUT
,
HttpMethod
.
PATCH
);
private
static
final
Se
t
<
HttpMethod
>
SUPPORTED_METHODS
=
EnumSet
.
of
(
HttpMethod
.
POST
,
HttpMethod
.
PUT
,
HttpMethod
.
PATCH
);
private
static
final
Object
NO_VALUE
=
new
Object
();
...
...
@@ -228,8 +228,8 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
}
if
(
body
==
NO_VALUE
)
{
if
(
!
SUPPORTED_METHODS
.
contains
(
httpMethod
)
||
(
noContentType
&&
inputMessage
.
getBody
()
==
null
))
{
if
(
httpMethod
==
null
||
!
SUPPORTED_METHODS
.
contains
(
httpMethod
)
||
(
noContentType
&&
inputMessage
.
getBody
()
==
null
))
{
return
null
;
}
throw
new
HttpMediaTypeNotSupportedException
(
contentType
,
this
.
allSupportedMediaTypes
);
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java
浏览文件 @
4261f34b
...
...
@@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.method.annotation;
import
java.io.IOException
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.net.URI
;
import
java.util.List
;
import
org.springframework.core.MethodParameter
;
...
...
@@ -122,9 +121,8 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
Object
body
=
readWithMessageConverters
(
webRequest
,
parameter
,
paramType
);
if
(
RequestEntity
.
class
==
parameter
.
getParameterType
())
{
URI
url
=
inputMessage
.
getURI
();
HttpMethod
httpMethod
=
inputMessage
.
getMethod
();
return
new
RequestEntity
<
Object
>(
body
,
inputMessage
.
getHeaders
(),
httpMethod
,
url
);
return
new
RequestEntity
<
Object
>(
body
,
inputMessage
.
getHeaders
(),
inputMessage
.
getMethod
(),
inputMessage
.
getURI
());
}
else
{
return
new
HttpEntity
<
Object
>(
body
,
inputMessage
.
getHeaders
());
...
...
@@ -172,8 +170,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
Object
body
=
responseEntity
.
getBody
();
if
(
responseEntity
instanceof
ResponseEntity
)
{
outputMessage
.
setStatusCode
(((
ResponseEntity
<?>)
responseEntity
).
getStatusCode
());
if
(
inputMessage
.
getMethod
().
equals
(
HttpMethod
.
GET
)
&&
isResourceNotModified
(
inputMessage
,
outputMessage
))
{
if
(
HttpMethod
.
GET
==
inputMessage
.
getMethod
()
&&
isResourceNotModified
(
inputMessage
,
outputMessage
))
{
outputMessage
.
setStatusCode
(
HttpStatus
.
NOT_MODIFIED
);
// Ensure headers are flushed, no body should be written.
outputMessage
.
flush
();
...
...
spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java
浏览文件 @
4261f34b
...
...
@@ -231,7 +231,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
logger
.
trace
(
"Processing request "
+
request
.
getURI
()
+
" with headers="
+
headers
);
}
try
{
if
(
!
HttpMethod
.
GET
.
equals
(
request
.
getMethod
()
))
{
if
(
HttpMethod
.
GET
!=
request
.
getMethod
(
))
{
response
.
setStatusCode
(
HttpStatus
.
METHOD_NOT_ALLOWED
);
response
.
getHeaders
().
setAllow
(
Collections
.
singleton
(
HttpMethod
.
GET
));
if
(
logger
.
isErrorEnabled
())
{
...
...
@@ -320,8 +320,8 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
". Supported versions: "
+
Arrays
.
toString
(
getSupportedVersions
()));
}
response
.
setStatusCode
(
HttpStatus
.
UPGRADE_REQUIRED
);
response
.
getHeaders
().
pu
t
(
WebSocketHttpHeaders
.
SEC_WEBSOCKET_VERSION
,
Arrays
.
asList
(
StringUtils
.
arrayToCommaDelimitedString
(
getSupportedVersions
()
)));
response
.
getHeaders
().
se
t
(
WebSocketHttpHeaders
.
SEC_WEBSOCKET_VERSION
,
StringUtils
.
arrayToCommaDelimitedString
(
getSupportedVersions
(
)));
}
/**
...
...
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java
浏览文件 @
4261f34b
...
...
@@ -544,7 +544,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
@Override
public
void
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
)
throws
IOException
{
if
(
HttpMethod
.
GET
.
equals
(
request
.
getMethod
()
))
{
if
(
HttpMethod
.
GET
==
request
.
getMethod
(
))
{
addNoCacheHeaders
(
response
);
if
(
checkOrigin
(
request
,
response
))
{
response
.
getHeaders
().
setContentType
(
new
MediaType
(
"application"
,
"json"
,
UTF8_CHARSET
));
...
...
@@ -554,7 +554,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
}
else
if
(
HttpMethod
.
OPTIONS
.
equals
(
request
.
getMethod
()
))
{
else
if
(
HttpMethod
.
OPTIONS
==
request
.
getMethod
(
))
{
if
(
checkOrigin
(
request
,
response
))
{
addCacheHeaders
(
response
);
response
.
setStatusCode
(
HttpStatus
.
NO_CONTENT
);
...
...
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java
浏览文件 @
4261f34b
...
...
@@ -247,8 +247,8 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
try
{
HttpMethod
supportedMethod
=
transportType
.
getHttpMethod
();
if
(
!
supportedMethod
.
equals
(
request
.
getMethod
()
))
{
if
(
HttpMethod
.
OPTIONS
.
equals
(
request
.
getMethod
()
)
&&
transportType
.
supportsCors
())
{
if
(
supportedMethod
!=
request
.
getMethod
(
))
{
if
(
HttpMethod
.
OPTIONS
==
request
.
getMethod
(
)
&&
transportType
.
supportsCors
())
{
if
(
checkOrigin
(
request
,
response
,
HttpMethod
.
OPTIONS
,
supportedMethod
))
{
response
.
setStatusCode
(
HttpStatus
.
NO_CONTENT
);
addCacheHeaders
(
response
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录