Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
fd43f473
Commit
fd43f473
authored
Nov 10, 2018
by
Dr Ian Preston
Committed by
Steven Allen
Nov 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
switch to new path format in p2p http proxy
License: MIT Signed-off-by:
Ian Preston
<
ianopolous@protonmail.com
>
parent
78c43fe6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
5 deletions
+16
-5
core/corehttp/proxy.go
core/corehttp/proxy.go
+16
-5
No files found.
core/corehttp/proxy.go
View file @
fd43f473
...
...
@@ -17,7 +17,7 @@ import (
// ProxyOption is an endpoint for proxying a HTTP request to another ipfs peer
func
ProxyOption
()
ServeOption
{
return
func
(
ipfsNode
*
core
.
IpfsNode
,
_
net
.
Listener
,
mux
*
http
.
ServeMux
)
(
*
http
.
ServeMux
,
error
)
{
mux
.
HandleFunc
(
"/p
roxy/htt
p/"
,
func
(
w
http
.
ResponseWriter
,
request
*
http
.
Request
)
{
mux
.
HandleFunc
(
"/p
2
p/"
,
func
(
w
http
.
ResponseWriter
,
request
*
http
.
Request
)
{
// parse request
parsedRequest
,
err
:=
parseRequest
(
request
)
if
err
!=
nil
{
...
...
@@ -49,16 +49,27 @@ type proxyRequest struct {
}
// from the url path parse the peer-ID, name and http path
// /proxy/http/$peer_id/$name/$http_path
// /p2p/$peer_id/http/$http_path
// or
// /p2p/$peer_id/x/$protocol/http/$http_path
func
parseRequest
(
request
*
http
.
Request
)
(
*
proxyRequest
,
error
)
{
path
:=
request
.
URL
.
Path
split
:=
strings
.
SplitN
(
path
,
"/"
,
6
)
if
len
(
split
)
<
6
{
split
:=
strings
.
SplitN
(
path
,
"/"
,
5
)
if
len
(
split
)
<
5
{
return
nil
,
fmt
.
Errorf
(
"Invalid request path '%s'"
,
path
)
}
return
&
proxyRequest
{
split
[
3
],
protocol
.
ID
(
split
[
4
]),
split
[
5
]},
nil
if
split
[
3
]
==
"http"
{
return
&
proxyRequest
{
split
[
2
],
protocol
.
ID
(
"/http"
),
split
[
4
]},
nil
}
split
=
strings
.
SplitN
(
path
,
"/"
,
7
)
if
split
[
3
]
!=
"x"
||
split
[
5
]
!=
"http"
{
return
nil
,
fmt
.
Errorf
(
"Invalid request path '%s'"
,
path
)
}
return
&
proxyRequest
{
split
[
2
],
protocol
.
ID
(
"/x/"
+
split
[
4
]
+
"/http"
),
split
[
6
]},
nil
}
func
handleError
(
w
http
.
ResponseWriter
,
msg
string
,
err
error
,
code
int
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment