Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
fcf635ba
提交
fcf635ba
authored
9月 26, 2018
作者:
Chris Boddy
提交者:
Steven Allen
10月 24, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[http_proxy_over_p2p] more tests, fix build
License: MIT Signed-off-by:
Chris Boddy
<
chris@boddy.im
>
上级
d4d00247
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
7 行删除
+32
-7
proxy.go
core/corehttp/proxy.go
+7
-6
proxy_test.go
core/corehttp/proxy_test.go
+25
-1
没有找到文件。
p2
p/proxy.go
→
core/corehtt
p/proxy.go
浏览文件 @
fcf635ba
package
p2
p
package
corehtt
p
import
(
"bufio"
...
...
@@ -8,6 +8,7 @@ import (
"strings"
core
"github.com/ipfs/go-ipfs/core"
protocol
"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
peer
"gx/ipfs/QmbNepETomvmXfz1X5pHNFD2QuPqnqi47dTd94QJWSorQ3/go-libp2p-peer"
)
...
...
@@ -62,19 +63,19 @@ type proxyRequest struct {
}
// from the url path parse the peer-ID, name and http path
// /http/$peer_id/$name/$http_path
// /
proxy/
http/$peer_id/$name/$http_path
func
parseRequest
(
request
*
http
.
Request
)
(
*
proxyRequest
,
error
)
{
path
:=
request
.
URL
.
Path
split
:=
strings
.
SplitN
(
path
,
"/"
,
6
)
if
split
[
2
]
!=
"http"
{
return
nil
,
fmt
.
Errorf
(
"Invalid proxy request protocol '%s'"
,
path
)
}
if
len
(
split
)
<
6
{
return
nil
,
fmt
.
Errorf
(
"Invalid request path '%s'"
,
path
)
}
if
split
[
2
]
!=
"http"
{
return
nil
,
fmt
.
Errorf
(
"Invalid proxy request protocol '%s'"
,
split
[
2
])
}
peerID
,
err
:=
peer
.
IDB58Decode
(
split
[
3
])
if
err
!=
nil
{
...
...
p2
p/proxy_test.go
→
core/corehtt
p/proxy_test.go
浏览文件 @
fcf635ba
package
p2
p
package
corehtt
p
import
(
"github.com/ipfs/go-ipfs/thirdparty/assert"
...
...
@@ -19,3 +19,27 @@ func TestParseRequest(t *testing.T) {
assert
.
True
(
parsed
.
name
==
"test-name"
,
t
,
"proxy request name"
)
assert
.
True
(
parsed
.
target
.
Pretty
()
==
"QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT"
,
t
,
"proxy request peer-id"
)
}
func
TestParseRequestInvalidProtocol
(
t
*
testing
.
T
)
{
url
:=
"http://localhost:5001/proxy/invalid/QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT/test-name/path/to/index.txt"
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
strings
.
NewReader
(
""
))
_
,
err
:=
parseRequest
(
req
)
if
err
==
nil
{
t
.
Fail
()
}
assert
.
True
(
err
.
Error
()
==
"Invalid proxy request protocol 'invalid'"
,
t
,
"fails with invalid proxy"
)
}
func
TestParseRequestInvalidPath
(
t
*
testing
.
T
)
{
url
:=
"http://localhost:5001/proxy/http/foobar"
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
strings
.
NewReader
(
""
))
_
,
err
:=
parseRequest
(
req
)
if
err
==
nil
{
t
.
Fail
()
}
assert
.
True
(
err
.
Error
()
==
"Invalid request path '/proxy/http/foobar'"
,
t
,
"fails with invalid path"
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论