Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
5ef2f42d
提交
5ef2f42d
authored
5月 17, 2017
作者:
Jeromy Johnson
提交者:
GitHub
5月 17, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3914 from jes/master
Add Suborigin header to gateway responses
上级
d6983801
cb2a38d8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
0 行删除
+34
-0
gateway_handler.go
core/corehttp/gateway_handler.go
+34
-0
没有找到文件。
core/corehttp/gateway_handler.go
浏览文件 @
5ef2f42d
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
cid
"gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
cid
"gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
routing
"gx/ipfs/QmafuecpeZp3k3sHJ5mUARHd4795revuadECQMkmHB8LfW/go-libp2p-routing"
routing
"gx/ipfs/QmafuecpeZp3k3sHJ5mUARHd4795revuadECQMkmHB8LfW/go-libp2p-routing"
node
"gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
node
"gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
multibase
"gx/ipfs/QmcxkxTVuURV2Ptse8TvkqH5BQDwV62X1x19JqqvbBzwUM/go-multibase"
)
)
const
(
const
(
...
@@ -210,6 +211,39 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
...
@@ -210,6 +211,39 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
// expose those headers
// expose those headers
w
.
Header
()
.
Set
(
"Access-Control-Expose-Headers"
,
"X-Stream-Output, X-Chunked-Output"
)
w
.
Header
()
.
Set
(
"Access-Control-Expose-Headers"
,
"X-Stream-Output, X-Chunked-Output"
)
// Suborigin header, sandboxes apps from each other in the browser (even
// though they are served from the same gateway domain).
//
// Omitted if the path was treated by IPNSHostnameOption(), for example
// a request for http://example.net/ would be changed to /ipns/example.net/,
// which would turn into an incorrect Suborigin header.
// In this case the correct thing to do is omit the header because it is already
// handled correctly without a Suborigin.
//
// NOTE: This is not yet widely supported by browsers.
if
!
ipnsHostname
{
// e.g.: 1="ipfs", 2="QmYuNaKwY...", ...
pathComponents
:=
strings
.
SplitN
(
urlPath
,
"/"
,
4
)
var
suboriginRaw
[]
byte
cidDecoded
,
err
:=
cid
.
Decode
(
pathComponents
[
2
])
if
err
!=
nil
{
// component 2 doesn't decode with cid, so it must be a hostname
suboriginRaw
=
[]
byte
(
strings
.
ToLower
(
pathComponents
[
2
]))
}
else
{
suboriginRaw
=
cidDecoded
.
Bytes
()
}
base32Encoded
,
err
:=
multibase
.
Encode
(
multibase
.
Base32
,
suboriginRaw
)
if
err
!=
nil
{
internalWebError
(
w
,
err
)
return
}
suborigin
:=
pathComponents
[
1
]
+
"000"
+
strings
.
ToLower
(
base32Encoded
)
w
.
Header
()
.
Set
(
"Suborigin"
,
suborigin
)
}
// set these headers _after_ the error, for we may just not have it
// set these headers _after_ the error, for we may just not have it
// and dont want the client to cache a 500 response...
// and dont want the client to cache a 500 response...
// and only if it's /ipfs!
// and only if it's /ipfs!
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论