Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sesemomo
spring-framework
提交
24e96b6c
S
spring-framework
项目概览
sesemomo
/
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,发现更多精彩内容 >>
提交
24e96b6c
编写于
7月 19, 2019
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '5.1.x'
上级
095fd5bc
a2446756
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
41 deletion
+49
-41
spring-web/src/main/java/org/springframework/web/client/RestOperations.java
...n/java/org/springframework/web/client/RestOperations.java
+10
-19
spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java
...mework/web/server/adapter/ForwardedHeaderTransformer.java
+2
-2
spring-web/src/test/java/org/springframework/web/server/adapter/ForwardedHeaderTransformerTests.java
...k/web/server/adapter/ForwardedHeaderTransformerTests.java
+16
-0
src/docs/asciidoc/integration.adoc
src/docs/asciidoc/integration.adoc
+21
-20
未找到文件。
spring-web/src/main/java/org/springframework/web/client/RestOperations.java
浏览文件 @
24e96b6c
/*
* 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.
...
...
@@ -153,8 +153,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param uriVariables the variables to expand the template
...
...
@@ -174,8 +173,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param uriVariables the variables to expand the template
...
...
@@ -195,8 +193,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @return the value for the {@code Location} header
...
...
@@ -215,8 +212,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param responseType the type of the return value
...
...
@@ -238,8 +234,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param responseType the type of the return value
...
...
@@ -260,8 +255,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param responseType the type of the return value
...
...
@@ -281,8 +275,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param uriVariables the variables to expand the template
...
...
@@ -303,8 +296,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @param uriVariables the variables to expand the template
...
...
@@ -324,8 +316,7 @@ public interface RestOperations {
* {@link org.springframework.util.MultiValueMap MultiValueMap} to create a multipart request.
* The values in the {@code MultiValueMap} can be any Object representing the body of the part,
* or an {@link org.springframework.http.HttpEntity HttpEntity} representing a part with body
* and headers. The {@code MultiValueMap} can be built conveniently using
* {@link org.springframework.http.client.MultipartBodyBuilder MultipartBodyBuilder}.
* and headers.
* @param url the URL
* @param request the Object to be POSTed (may be {@code null})
* @return the converted object
...
...
spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java
浏览文件 @
24e96b6c
/*
* 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.
...
...
@@ -96,7 +96,7 @@ public class ForwardedHeaderTransformer implements Function<ServerHttpRequest, S
builder
.
uri
(
uri
);
String
prefix
=
getForwardedPrefix
(
request
);
if
(
prefix
!=
null
)
{
builder
.
path
(
prefix
+
uri
.
getPath
());
builder
.
path
(
prefix
+
uri
.
get
Raw
Path
());
builder
.
contextPath
(
prefix
);
}
}
...
...
spring-web/src/test/java/org/springframework/web/server/adapter/ForwardedHeaderTransformerTests.java
浏览文件 @
24e96b6c
...
...
@@ -90,6 +90,22 @@ public class ForwardedHeaderTransformerTests {
assertForwardedHeadersRemoved
(
request
);
}
@Test
// gh-23305
public
void
xForwardedPrefixShouldNotLeadToDecodedPath
()
throws
Exception
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"X-Forwarded-Prefix"
,
"/prefix"
);
ServerHttpRequest
request
=
MockServerHttpRequest
.
method
(
HttpMethod
.
GET
,
new
URI
(
"https://example.com/a%20b?q=a%2Bb"
))
.
headers
(
headers
)
.
build
();
request
=
this
.
requestMutator
.
apply
(
request
);
assertThat
(
request
.
getURI
()).
isEqualTo
(
new
URI
(
"https://example.com/prefix/a%20b?q=a%2Bb"
));
assertThat
(
request
.
getPath
().
value
()).
isEqualTo
(
"/prefix/a%20b"
);
assertForwardedHeadersRemoved
(
request
);
}
@Test
public
void
xForwardedPrefixTrailingSlash
()
throws
Exception
{
HttpHeaders
headers
=
new
HttpHeaders
();
...
...
src/docs/asciidoc/integration.adoc
浏览文件 @
24e96b6c
...
...
@@ -1211,41 +1211,42 @@ to serialize only a subset of the object properties, as the following example sh
[[rest-template-multipart]]
===== Multipart
To send multipart data, you need to provide a `MultiValueMap
<String
,
?
>
` whose values are
either `Object` instances that represent part content or `HttpEntity` instances that represent the content and
headers for a part. `MultipartBodyBuilder` provides a convenient API to prepare a
multipart request, as the following example shows:
To send multipart data, you need to provide a `MultiValueMap
<String
,
Object
>
` whose values
may be an `Object` for part content, a `Resource` for a file part, or an `HttpEntity` for
part content with headers. For example:
[source,java,intent=0]
[subs="verbatim,quotes"]
----
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("fieldPart", "fieldValue");
builder.part("filePart", new FileSystemResource("...logo.png"));
builder.part("jsonPart", new Person("Jason"));
MultiValueMap
<String
,
Object
>
parts = new LinkedMultiValueMap
<>
();
MultiValueMap
<String
,
HttpEntity
<?
>
> parts = builder.build();
parts.add("fieldPart", "fieldValue");
parts.add("filePart", new FileSystemResource("...logo.png"));
parts.add("jsonPart", new Person("Jason"));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
parts.add("xmlPart", new HttpEntity
<>
(myBean, headers));
----
In most cases, you do not have to specify the `Content-Type` for each part. The content
type is determined automatically based on the `HttpMessageConverter` chosen to serialize it
or, in the case of a `Resource`, based on the file extension. If necessary, you can
explicitly provide the `MediaType` to use for each part through one of the overloaded
builder `part` methods.
type is determined automatically based on the `HttpMessageConverter` chosen to serialize
it or, in the case of a `Resource` based on the file extension. If necessary, you can
explicitly provide the `MediaType` with an `HttpEntity` wrapper.
Once the `MultiValueMap` is ready, you can pass it to the `RestTemplate`, as
the following example shows
:
Once the `MultiValueMap` is ready, you can pass it to the `RestTemplate`, as
show below
:
[source,java,intent=0]
[subs="verbatim,quotes"]
----
Multi
partBodyBuilder builder
= ...;
template.postForObject("https://example.com/upload",
builder.build()
, Void.class);
Multi
ValueMap
<String
,
Object
>
parts
= ...;
template.postForObject("https://example.com/upload",
parts
, Void.class);
----
If the `MultiValueMap` contains at least one non-`String` value,
which could also be
represent regular form data (that is, `application/x-www-form-urlencoded`), you need not
set the `Content-Type` to `multipart/form-data`. This is always the case when you use
`MultipartBodyBuilder` which ensures an `HttpEntity` wrapper
.
If the `MultiValueMap` contains at least one non-`String` value,
the `Content-Type` is set
to `multipart/form-data` by the `FormHttpMessageConverter`. If the `MultiValueMap` has
`String` values the `Content-Type` is defaulted to `application/x-www-form-urlencoded`.
If necessary the `Content-Type` may also be set explicitly
.
[[rest-async-resttemplate]]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录