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
52bc2982
Commit
52bc2982
authored
Dec 18, 2017
by
keks
Committed by
Jeromy
Jan 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ServerNameOption
License: MIT Signed-off-by:
keks
<
keks@cryptoscope.co
>
parent
8294f0a3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
15 deletions
+16
-15
TODO.md
TODO.md
+0
-1
cmd/ipfs/daemon.go
cmd/ipfs/daemon.go
+2
-2
core/corehttp/commands.go
core/corehttp/commands.go
+6
-4
core/corehttp/option_test.go
core/corehttp/option_test.go
+8
-8
No files found.
TODO.md
View file @
52bc2982
# TODO before merge
-
return an error if a http client connects with User-Agent ~ '^/go-ipfs/
`
but not our exact version
cmd/ipfs/daemon.go
View file @
52bc2982
...
...
@@ -433,8 +433,8 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (error, <-chan error
var
opts
=
[]
corehttp
.
ServeOption
{
corehttp
.
MetricsCollectionOption
(
"api"
),
corehttp
.
CheckVersionOption
(),
corehttp
.
CommandsOption
(
*
cctx
),
//corehttp.CheckVersionOption(),
//corehttp.ServerNameOption("go-ipfs/" + config.CurrentVersionNumber),
corehttp
.
WebUIOption
,
gatewayOpt
,
...
...
@@ -529,11 +529,11 @@ func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (error, <-chan e
var
opts
=
[]
corehttp
.
ServeOption
{
corehttp
.
MetricsCollectionOption
(
"gateway"
),
corehttp
.
CheckVersionOption
(),
corehttp
.
CommandsROOption
(
*
cctx
),
corehttp
.
VersionOption
(),
corehttp
.
IPNSHostnameOption
(),
corehttp
.
GatewayOption
(
writable
,
"/ipfs"
,
"/ipns"
),
corehttp
.
CheckVersionOption
(),
}
if
len
(
cfg
.
Gateway
.
RootRedirect
)
>
0
{
...
...
core/corehttp/commands.go
View file @
52bc2982
...
...
@@ -144,11 +144,13 @@ func CommandsROOption(cctx oldcmds.Context) ServeOption {
func
CheckVersionOption
()
ServeOption
{
daemonVersion
:=
config
.
ApiVersion
return
ServeOption
(
func
(
n
*
core
.
IpfsNode
,
l
net
.
Listener
,
nex
t
*
http
.
ServeMux
)
(
*
http
.
ServeMux
,
error
)
{
return
ServeOption
(
func
(
n
*
core
.
IpfsNode
,
l
net
.
Listener
,
paren
t
*
http
.
ServeMux
)
(
*
http
.
ServeMux
,
error
)
{
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
"/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
parent
.
HandleFunc
(
"/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
strings
.
HasPrefix
(
r
.
URL
.
Path
,
APIPath
)
{
pth
:=
path
.
SplitList
(
r
.
URL
.
Path
[
len
(
APIPath
)
:
])
cmdqry
:=
r
.
URL
.
Path
[
len
(
APIPath
)
:
]
pth
:=
path
.
SplitList
(
cmdqry
)
// backwards compatibility to previous version check
if
pth
[
1
]
!=
"version"
{
clientVersion
:=
r
.
UserAgent
()
...
...
@@ -160,7 +162,7 @@ func CheckVersionOption() ServeOption {
}
}
next
.
ServeHTTP
(
w
,
r
)
mux
.
ServeHTTP
(
w
,
r
)
})
return
mux
,
nil
...
...
core/corehttp/option_test.go
View file @
52bc2982
...
...
@@ -41,8 +41,13 @@ func TestCheckVersionOption(t *testing.T) {
r
.
Header
.
Add
(
"User-Agent"
,
tc
.
userAgent
)
// old version, should fail
called
:=
false
inner
:=
http
.
NewServeMux
()
inner
.
HandleFunc
(
"/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
root
:=
http
.
NewServeMux
()
mux
,
err
:=
CheckVersionOption
()(
nil
,
nil
,
root
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
mux
.
HandleFunc
(
"/"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
called
=
true
if
!
tc
.
shouldHandle
{
t
.
Error
(
"handler was called even though version didn't match"
)
...
...
@@ -51,14 +56,9 @@ func TestCheckVersionOption(t *testing.T) {
}
})
mux
,
err
:=
CheckVersionOption
()(
nil
,
nil
,
inner
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
w
:=
httptest
.
NewRecorder
()
mux
.
ServeHTTP
(
w
,
r
)
root
.
ServeHTTP
(
w
,
r
)
if
tc
.
shouldHandle
&&
!
called
{
t
.
Error
(
"handler wasn't called even though it should have"
)
...
...
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