Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
85060236
提交
85060236
authored
3月 14, 2016
作者:
Jeromy Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix double transfer encoding head problem
License: MIT Signed-off-by:
Jeromy Johnson
<
why@ipfs.io
>
上级
286a5968
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
33 行增加
和
25 行删除
+33
-25
client.go
commands/http/client.go
+1
-1
handler.go
commands/http/handler.go
+18
-16
handler_test.go
commands/http/handler_test.go
+0
-2
t0110-gateway.sh
test/sharness/t0110-gateway.sh
+10
-0
t0230-channel-streaming-http-content-type.sh
test/sharness/t0230-channel-streaming-http-content-type.sh
+4
-6
没有找到文件。
commands/http/client.go
浏览文件 @
85060236
...
...
@@ -159,7 +159,7 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
contentType
:=
httpRes
.
Header
.
Get
(
contentTypeHeader
)
contentType
=
strings
.
Split
(
contentType
,
";"
)[
0
]
lengthHeader
:=
httpRes
.
Header
.
Get
(
c
ontentLengthHeader
)
lengthHeader
:=
httpRes
.
Header
.
Get
(
extraC
ontentLengthHeader
)
if
len
(
lengthHeader
)
>
0
{
length
,
err
:=
strconv
.
ParseUint
(
lengthHeader
,
10
,
64
)
if
err
!=
nil
{
...
...
commands/http/handler.go
浏览文件 @
85060236
...
...
@@ -41,20 +41,23 @@ var (
)
const
(
StreamErrHeader
=
"X-Stream-Error"
streamHeader
=
"X-Stream-Output"
channelHeader
=
"X-Chunked-Output"
uaHeader
=
"User-Agent
"
contentTypeHeader
=
"Content-Type
"
content
LengthHeader
=
"Content-Length
"
contentDispHeader
=
"Content-Disposition"
transferEncodingHeader
=
"Transfer-Encoding"
applicationJson
=
"application/json"
applicationOctetStream
=
"application/octet-stream"
plainText
=
"text/plain"
originHeader
=
"origin"
StreamErrHeader
=
"X-Stream-Error"
streamHeader
=
"X-Stream-Output"
channelHeader
=
"X-Chunked-Output"
extraContentLengthHeader
=
"X-Content-Length
"
uaHeader
=
"User-Agent
"
content
TypeHeader
=
"Content-Type
"
contentDispHeader
=
"Content-Disposition"
transferEncodingHeader
=
"Transfer-Encoding"
applicationJson
=
"application/json"
applicationOctetStream
=
"application/octet-stream"
plainText
=
"text/plain"
originHeader
=
"origin"
)
var
AllowedExposedHeadersArr
=
[]
string
{
streamHeader
,
channelHeader
,
extraContentLengthHeader
}
var
AllowedExposedHeaders
=
strings
.
Join
(
AllowedExposedHeadersArr
,
", "
)
const
(
ACAOrigin
=
"Access-Control-Allow-Origin"
ACAMethods
=
"Access-Control-Allow-Methods"
...
...
@@ -241,7 +244,7 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
h
.
Set
(
"Trailer"
,
StreamErrHeader
)
if
res
.
Length
()
>
0
{
h
.
Set
(
contentLengthHeader
,
strconv
.
FormatUint
(
res
.
Length
(),
10
))
h
.
Set
(
"X-Content-Length"
,
strconv
.
FormatUint
(
res
.
Length
(),
10
))
}
if
_
,
ok
:=
res
.
Output
()
.
(
io
.
Reader
);
ok
{
...
...
@@ -268,12 +271,11 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
}
h
.
Set
(
contentTypeHeader
,
mime
)
h
.
Set
(
transferEncodingHeader
,
"chunked"
)
// set 'allowed' headers
h
.
Set
(
"Access-Control-Allow-Headers"
,
"X-Stream-Output, X-Chunked-Output"
)
h
.
Set
(
"Access-Control-Allow-Headers"
,
AllowedExposedHeaders
)
// expose those headers
h
.
Set
(
"Access-Control-Expose-Headers"
,
"X-Stream-Output, X-Chunked-Output"
)
h
.
Set
(
"Access-Control-Expose-Headers"
,
AllowedExposedHeaders
)
if
r
.
Method
==
"HEAD"
{
// after all the headers.
return
...
...
commands/http/handler_test.go
浏览文件 @
85060236
...
...
@@ -11,8 +11,6 @@ import (
coremock
"github.com/ipfs/go-ipfs/core/mock"
)
const
AllowedExposedHeaders
=
"X-Stream-Output, X-Chunked-Output"
func
assertHeaders
(
t
*
testing
.
T
,
resHeaders
http
.
Header
,
reqHeaders
map
[
string
]
string
)
{
for
name
,
value
:=
range
reqHeaders
{
if
resHeaders
.
Get
(
name
)
!=
value
{
...
...
test/sharness/t0110-gateway.sh
浏览文件 @
85060236
...
...
@@ -91,6 +91,16 @@ test_expect_success "log output looks good" '
grep "log API client connected" log_out
'
test_expect_success
"GET /api/v0/version succeeds"
'
curl -v "http://127.0.0.1:$apiport/api/v0/version" 2> version_out
'
test_expect_success
"output only has one transfer encoding header"
'
grep "Transfer-Encoding: chunked" version_out | wc -l > tecount_out &&
echo " 1" > tecount_exp &&
test_cmp tecount_out tecount_exp
'
test_expect_success
"setup index hash"
'
mkdir index &&
echo "<p></p>" > index/index.html &&
...
...
test/sharness/t0230-channel-streaming-http-content-type.sh
浏览文件 @
85060236
...
...
@@ -21,12 +21,11 @@ test_ls_cmd() {
test_expect_success
"Text encoded channel-streaming command output looks good"
'
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output
, X-Content-Length
\r\n" >>expected_output &&
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output
, X-Content-Length
\r\n" >>expected_output &&
printf "Content-Type: text/plain\r\n" >>expected_output &&
printf "Server: go-ipfs/%s\r\n" $(ipfs version -n) >>expected_output &&
printf "Trailer: X-Stream-Error\r\n" >>expected_output &&
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
printf "X-Chunked-Output: 1\r\n" >>expected_output &&
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
printf "\r\n" >>expected_output &&
...
...
@@ -44,12 +43,11 @@ test_ls_cmd() {
test_expect_success
"JSON encoded channel-streaming command output looks good"
'
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output
, X-Content-Length
\r\n" >>expected_output &&
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output
, X-Content-Length
\r\n" >>expected_output &&
printf "Content-Type: application/json\r\n" >>expected_output &&
printf "Server: go-ipfs/%s\r\n" $(ipfs version -n) >>expected_output &&
printf "Trailer: X-Stream-Error\r\n" >>expected_output &&
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
printf "X-Chunked-Output: 1\r\n" >>expected_output &&
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
printf "\r\n" >>expected_output &&
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论