Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e05bb488
提交
e05bb488
authored
10月 24, 2018
作者:
Chris Boddy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[http_proxy_over_p2p] url-decode the proxy name and fix test
License: MIT Signed-off-by:
Chris Boddy
<
chris@boddy.im
>
上级
dd46232f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
18 行删除
+32
-18
proxy.go
core/corehttp/proxy.go
+6
-1
t0184-http-proxy-over-p2p.sh
test/sharness/t0184-http-proxy-over-p2p.sh
+26
-17
没有找到文件。
core/corehttp/proxy.go
浏览文件 @
e05bb488
...
...
@@ -57,8 +57,13 @@ func parseRequest(request *http.Request) (*proxyRequest, error) {
if
len
(
split
)
<
6
{
return
nil
,
fmt
.
Errorf
(
"Invalid request path '%s'"
,
path
)
}
//url-decode the name
decodedName
,
err
:=
url
.
PathUnescape
(
split
[
4
])
if
err
!=
nil
{
return
nil
,
err
}
return
&
proxyRequest
{
split
[
3
],
protocol
.
ID
(
split
[
4
]
),
split
[
5
]},
nil
return
&
proxyRequest
{
split
[
3
],
protocol
.
ID
(
decodedName
),
split
[
5
]},
nil
}
func
handleError
(
w
http
.
ResponseWriter
,
msg
string
,
err
error
,
code
int
)
{
...
...
test/sharness/t0184-http-proxy-over-p2p.sh
浏览文件 @
e05bb488
...
...
@@ -5,26 +5,41 @@ test_description="Test http proxy over p2p"
.
lib/test-lib.sh
WEB_SERVE_PORT
=
5099
function
show_logs
()
{
echo
"*****************"
echo
" RECEIVER LOG "
echo
"*****************"
cat
$RECEIVER_LOG
echo
"*****************"
echo
" SENDER LOG "
echo
"*****************"
cat
$SENDER_LOG
echo
"*****************"
echo
"REMOTE_SERVER LOG"
echo
$REMOTE_SERVER_LOG
echo
"*****************"
cat
$REMOTE_SERVER_LOG
}
function
serve_http_once
()
{
#
# one shot http server (via nc) with static body
#
local
body
=
$1
local
status_code
=
${
2
:-
"200 OK"
}
local
length
=
$(
expr 1 +
${#
body
}
)
local
length
=
$(
(
1
+
${#
body
})
)
REMOTE_SERVER_LOG
=
$(
mktemp
)
echo
-e
"HTTP/1.1
$status_code
\n
Content-length:
$length
\n\n
$body
"
| nc
-l
$WEB_SERVE_PORT
>
$REMOTE_SERVER_LOG
&
echo
-e
"HTTP/1.1
$status_code
\n
Content-length:
$length
\n\n
$body
"
| nc
-l
$WEB_SERVE_PORT
2>&1
>
$REMOTE_SERVER_LOG
&
REMOTE_SERVER_PID
=
$!
}
function
setup_receiver_ipfs
()
{
#
# setup RECEIVER IPFS daemon
#
local
IPFS_PATH
=
$(
mktemp
-d
)
RECEIVER_LOG
=
$IPFS_PATH
/ipfs.log
ipfs init
>>
$RECEIVER_LOG
2>&1
ipfs config
--json
Experimental.Libp2pStreamMounting
true
>>
$RECEIVER_LOG
2>&1
ipfs config
--json
Addresses.API
"
\"
/ip4/127.0.0.1/tcp/6001
\"
"
>>
$RECEIVER_LOG
2>&1
...
...
@@ -34,7 +49,7 @@ function setup_receiver_ipfs() {
RECEIVER_PID
=
$!
# wait for daemon to start.. maybe?
# ipfs id returns empty string if we don't wait here..
sleep
5
sleep
10
RECEIVER_ID
=
$(
ipfs id
-f
"<id>"
)
#
# start a p2p listener on RECIVER to the HTTP server with our content
...
...
@@ -54,7 +69,7 @@ function setup_sender_ipfs() {
ipfs config
--json
Experimental.P2pHttpProxy
true
>>
$RECEIVER_LOG
2>&1
ipfs daemon
>>
$SENDER_LOG
2>&1 &
SENDER_PID
=
$!
sleep
5
sleep
10
}
function
setup_sender_and_receiver_ipfs
()
{
...
...
@@ -125,7 +140,7 @@ function curl_send_multipart_form_request() {
#
# send multipart form request
#
STATUS_CODE
=
$(
curl
-
s
-F
file
=
@
$FILE_PATH
http://localhost:5001/proxy/http/
$RECEIVER_ID
/test/index.txt
)
STATUS_CODE
=
$(
curl
-
v
-F
file
=
@
$FILE_PATH
http://localhost:5001/proxy/http/
$RECEIVER_ID
/test/index.txt
)
#
# check status code
#
...
...
@@ -140,14 +155,7 @@ function curl_send_multipart_form_request() {
if
!
grep
"POST /index.txt"
$REMOTE_SERVER_LOG
>
/dev/null
;
then
echo
"Remote server request method/resource path was incorrect"
return
1
fi
#
# check content received
#
if
!
grep
"
$FILE_CONTENT
"
$REMOTE_SERVER_LOG
>
/dev/null
;
then
echo
"form-data-content was not correct"
show_logs
return
1
fi
#
...
...
@@ -156,12 +164,12 @@ function curl_send_multipart_form_request() {
if
!
grep
"Content-Type: multipart/form-data;"
$REMOTE_SERVER_LOG
>
/dev/null
;
then
echo
"Request content-type was not multipart/form-data"
show_logs
return
1
fi
return
0
}
teardown_sender_and_receiver
test_expect_success
'handle proxy http request propogates error response from remote'
'
serve_http_once "SORRY GUYS, I LOST IT" "404 Not Found" &&
setup_sender_and_receiver_ipfs &&
...
...
@@ -182,10 +190,11 @@ serve_http_once "THE WOODS ARE LOVELY DARK AND DEEP" &&
curl_send_proxy_request_and_check_response 200 "THE WOODS ARE LOVELY DARK AND DEEP"
'
teardown_sender_and_receiver
teardown_remote_server
test_expect_success
'handle proxy http request invalid request'
'
setup_sender_and_receiver_ipfs &&
curl_check_response_code 400 DERPDERPDERP
curl_check_response_code 400 DERPDERPDERP
'
teardown_sender_and_receiver
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论