Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
9b0cc00c
R
retrofit
项目概览
wd1105040417
/
retrofit
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
retrofit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b0cc00c
编写于
11月 23, 2014
作者:
J
Jesse Wilson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #666 from square/jw/iterable-headers
Add support for iterable headers.
上级
0f59dc76
ac07d1de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
4 deletion
+50
-4
retrofit/src/main/java/retrofit/RequestBuilder.java
retrofit/src/main/java/retrofit/RequestBuilder.java
+18
-3
retrofit/src/main/java/retrofit/http/Header.java
retrofit/src/main/java/retrofit/http/Header.java
+2
-1
retrofit/src/test/java/retrofit/RequestBuilderTest.java
retrofit/src/test/java/retrofit/RequestBuilderTest.java
+30
-0
未找到文件。
retrofit/src/main/java/retrofit/RequestBuilder.java
浏览文件 @
9b0cc00c
...
...
@@ -253,11 +253,26 @@ final class RequestBuilder implements RequestInterceptor.RequestFacade {
}
else
if
(
annotationType
==
retrofit
.
http
.
Header
.
class
)
{
if
(
value
!=
null
)
{
// Skip null values.
String
name
=
((
retrofit
.
http
.
Header
)
annotation
).
value
();
addHeader
(
name
,
value
.
toString
());
if
(
value
instanceof
Iterable
)
{
for
(
Object
iterableValue
:
(
Iterable
<?>)
value
)
{
if
(
iterableValue
!=
null
)
{
// Skip null values.
addHeader
(
name
,
iterableValue
.
toString
());
}
}
}
else
if
(
value
.
getClass
().
isArray
())
{
for
(
int
x
=
0
,
arrayLength
=
Array
.
getLength
(
value
);
x
<
arrayLength
;
x
++)
{
Object
arrayValue
=
Array
.
get
(
value
,
x
);
if
(
arrayValue
!=
null
)
{
// Skip null values.
addHeader
(
name
,
arrayValue
.
toString
());
}
}
}
else
{
addHeader
(
name
,
value
.
toString
());
}
}
}
else
if
(
annotationType
==
Field
.
class
)
{
String
name
=
((
Field
)
annotation
).
value
();
if
(
value
!=
null
)
{
// Skip null values.
String
name
=
((
Field
)
annotation
).
value
();
if
(
value
instanceof
Iterable
)
{
for
(
Object
iterableValue
:
(
Iterable
<?>)
value
)
{
if
(
iterableValue
!=
null
)
{
// Skip null values.
...
...
@@ -290,8 +305,8 @@ final class RequestBuilder implements RequestInterceptor.RequestFacade {
}
}
}
else
if
(
annotationType
==
Part
.
class
)
{
String
name
=
((
Part
)
annotation
).
value
();
if
(
value
!=
null
)
{
// Skip null values.
String
name
=
((
Part
)
annotation
).
value
();
String
transferEncoding
=
((
Part
)
annotation
).
encoding
();
if
(
value
instanceof
TypedOutput
)
{
multipartBody
.
addPart
(
name
,
transferEncoding
,
(
TypedOutput
)
value
);
...
...
retrofit/src/main/java/retrofit/http/Header.java
浏览文件 @
9b0cc00c
...
...
@@ -30,7 +30,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* void foo(@Header("Accept-Language") String lang, Callback<Response> cb);
* </pre>
* <p>
* Header parameters may be {@code null} which will omit them from the request.
* Header parameters may be {@code null} which will omit them from the request. Passing a
* {@link java.util.List List} or array will result in a header for each non-{@code null} item.
* <p>
* <strong>Note:</strong> Headers do not overwrite each other. All headers with the same name will
* be included in the request.
...
...
retrofit/src/test/java/retrofit/RequestBuilderTest.java
浏览文件 @
9b0cc00c
...
...
@@ -1680,6 +1680,36 @@ public class RequestBuilderTest {
assertThat
(
request
.
getBody
()).
isNull
();
}
@Test
public
void
headerParamList
()
{
class
Example
{
@GET
(
"/foo/bar/"
)
//
Response
method
(
@retrofit
.
http
.
Header
(
"foo"
)
List
<
String
>
kit
)
{
return
null
;
}
}
Request
request
=
buildRequest
(
Example
.
class
,
Arrays
.
asList
(
"bar"
,
null
,
"baz"
));
assertThat
(
request
.
getMethod
()).
isEqualTo
(
"GET"
);
assertThat
(
request
.
getHeaders
())
//
.
containsExactly
(
new
Header
(
"foo"
,
"bar"
),
new
Header
(
"foo"
,
"baz"
));
assertThat
(
request
.
getUrl
()).
isEqualTo
(
"http://example.com/foo/bar/"
);
assertThat
(
request
.
getBody
()).
isNull
();
}
@Test
public
void
headerParamArray
()
{
class
Example
{
@GET
(
"/foo/bar/"
)
//
Response
method
(
@retrofit
.
http
.
Header
(
"foo"
)
String
[]
kit
)
{
return
null
;
}
}
Request
request
=
buildRequest
(
Example
.
class
,
(
Object
)
new
String
[]
{
"bar"
,
null
,
"baz"
});
assertThat
(
request
.
getMethod
()).
isEqualTo
(
"GET"
);
assertThat
(
request
.
getHeaders
())
//
.
containsExactly
(
new
Header
(
"foo"
,
"bar"
),
new
Header
(
"foo"
,
"baz"
));
assertThat
(
request
.
getUrl
()).
isEqualTo
(
"http://example.com/foo/bar/"
);
assertThat
(
request
.
getBody
()).
isNull
();
}
@Test
public
void
contentTypeAnnotationHeaderOverrides
()
{
class
Example
{
@POST
(
"/"
)
//
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录