Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
5abd144b
提交
5abd144b
authored
3月 14, 2019
作者:
Steven Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config: update for new gateway options
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
上级
3632a6d4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
42 行增加
和
45 行删除
+42
-45
gateway_handler.go
core/corehttp/gateway_handler.go
+0
-28
hostname.go
core/corehttp/hostname.go
+39
-2
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-14
没有找到文件。
core/corehttp/gateway_handler.go
浏览文件 @
5abd144b
...
...
@@ -34,34 +34,6 @@ const (
ipnsPathPrefix
=
"/ipns/"
)
type
GatewaySpec
struct
{
// PathPrefixes list the set of path prefixes that should be handled by
// the gateway logic.
PathPrefixes
[]
string
// UseSubdomains indicates whether or not this gateway uses subdomains
// for IPFS resources instead of paths. That is: http://CID.ipfs.GATEWAY/...
//
// If this flag is set, any /ipns/$id and/or /ipfs/$id paths in PathPrefixes
// will be permanently redirected to http://$id.[ipns|ipfs].$gateway/.
//
// We do not support using both paths and subdomains for a single domain
// for security reasons.
UseSubdomains
bool
}
var
DefaultGatewaySpec
=
GatewaySpec
{
PathPrefixes
:
[]
string
{
ipfsPathPrefix
,
ipnsPathPrefix
,
"/api/"
},
UseSubdomains
:
false
,
}
// TODO(steb): Configurable
var
KnownGateways
=
map
[
string
]
GatewaySpec
{
"ipfs.io"
:
DefaultGatewaySpec
,
"gateway.ipfs.io"
:
DefaultGatewaySpec
,
"localhost:8080"
:
DefaultGatewaySpec
,
}
// gatewayHandler is a HTTP handler that serves IPFS objects (accessible by default at /ipfs/<path>)
// (it serves requests like GET /ipfs/QmVRzPKPzNtSrEzBFm2UZfxmPAgnaLke4DMcerbsGGSaFe/link)
type
gatewayHandler
struct
{
...
...
core/corehttp/hostname.go
浏览文件 @
5abd144b
...
...
@@ -10,14 +10,51 @@ import (
core
"github.com/ipfs/go-ipfs/core"
namesys
"github.com/ipfs/go-ipfs/namesys"
config
"github.com/ipfs/go-ipfs-config"
nsopts
"github.com/ipfs/interface-go-ipfs-core/options/namesys"
isd
"github.com/jbenet/go-is-domain"
)
var
defaultGatewaySpec
=
config
.
GatewaySpec
{
PathPrefixes
:
[]
string
{
ipfsPathPrefix
,
ipnsPathPrefix
,
"/api/"
},
UseSubdomains
:
false
,
}
var
defaultKnownGateways
=
map
[
string
]
config
.
GatewaySpec
{
"ipfs.io"
:
defaultGatewaySpec
,
"gateway.ipfs.io"
:
defaultGatewaySpec
,
"dweb.link"
:
config
.
GatewaySpec
{
PathPrefixes
:
[]
string
{
ipfsPathPrefix
,
ipnsPathPrefix
},
UseSubdomains
:
true
,
},
}
// HostnameOption rewrites an incoming request based on the Host header.
func
HostnameOption
()
ServeOption
{
return
func
(
n
*
core
.
IpfsNode
,
_
net
.
Listener
,
mux
*
http
.
ServeMux
)
(
*
http
.
ServeMux
,
error
)
{
childMux
:=
http
.
NewServeMux
()
cfg
,
err
:=
n
.
Repo
.
Config
()
if
err
!=
nil
{
return
nil
,
err
}
knownGateways
:=
make
(
map
[
string
]
config
.
GatewaySpec
,
len
(
defaultKnownGateways
)
+
len
(
cfg
.
Gateway
.
PublicGateways
),
)
for
host
,
gw
:=
range
defaultKnownGateways
{
knownGateways
[
host
]
=
gw
}
for
host
,
gw
:=
range
cfg
.
Gateway
.
PublicGateways
{
if
gw
==
nil
{
// Allows the user to remove gateways but _also_
// allows us to continuously update the list.
delete
(
knownGateways
,
host
)
}
else
{
knownGateways
[
host
]
=
*
gw
}
}
mux
.
HandleFunc
(
"/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
n
.
Context
())
defer
cancel
()
...
...
@@ -38,7 +75,7 @@ func HostnameOption() ServeOption {
// would "just work". Should we try this?
// Is this one of our "known gateways"?
if
gw
,
ok
:=
K
nownGateways
[
r
.
Host
];
ok
{
if
gw
,
ok
:=
k
nownGateways
[
r
.
Host
];
ok
{
// This is a known gateway but we're not using
// the subdomain feature.
...
...
@@ -63,7 +100,7 @@ func HostnameOption() ServeOption {
// Looks like we're using subdomains.
// Again, is this a known gateway that supports subdomains?
if
gw
,
ok
:=
K
nownGateways
[
host
];
ok
&&
gw
.
UseSubdomains
{
if
gw
,
ok
:=
k
nownGateways
[
host
];
ok
&&
gw
.
UseSubdomains
{
// Yes, serve the request (and rewrite the path to not use subdomains).
r
.
URL
.
Path
=
pathPrefix
+
r
.
URL
.
Path
...
...
go.mod
浏览文件 @
5abd144b
...
...
@@ -33,7 +33,7 @@ require (
github.com/ipfs/go-ipfs-chunker v0.0.1
github.com/ipfs/go-ipfs-cmdkit v0.0.1
github.com/ipfs/go-ipfs-cmds v0.0.4
github.com/ipfs/go-ipfs-config v0.0.
1
github.com/ipfs/go-ipfs-config v0.0.
2-0.20190315044135-de0accf5476b
github.com/ipfs/go-ipfs-ds-help v0.0.1
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
...
...
go.sum
浏览文件 @
5abd144b
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论