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
2cc5ce45
Commit
2cc5ce45
authored
Mar 22, 2017
by
Jeromy Johnson
Committed by
GitHub
Mar 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3777 from ipfs/fix/gateway-status-codes
Return 404 Not Found for failed path resolutions
parents
2de21bc0
807ffb91
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
14 deletions
+10
-14
commands/response.go
commands/response.go
+1
-0
core/commands/dns.go
core/commands/dns.go
+4
-0
core/corehttp/gateway_handler.go
core/corehttp/gateway_handler.go
+4
-13
core/corehttp/gateway_test.go
core/corehttp/gateway_test.go
+1
-1
No files found.
commands/response.go
View file @
2cc5ce45
...
...
@@ -17,6 +17,7 @@ type ErrorType uint
const
(
ErrNormal
ErrorType
=
iota
// general errors
ErrClient
// error was caused by the client, (e.g. invalid CLI usage)
ErrNotFound
// == HTTP 404 Not Found
ErrImplementation
// programmer error in the server
// TODO: add more types of errors for better error-specific handling
)
...
...
core/commands/dns.go
View file @
2cc5ce45
...
...
@@ -60,6 +60,10 @@ The resolver can recursively resolve:
depth
=
namesys
.
DefaultDepthLimit
}
output
,
err
:=
resolver
.
ResolveN
(
req
.
Context
(),
name
,
depth
)
if
err
==
namesys
.
ErrResolveFailed
{
res
.
SetError
(
err
,
cmds
.
ErrNotFound
)
return
}
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
...
...
core/corehttp/gateway_handler.go
View file @
2cc5ce45
...
...
@@ -18,7 +18,6 @@ import (
chunk
"github.com/ipfs/go-ipfs/importer/chunk"
dag
"github.com/ipfs/go-ipfs/merkledag"
dagutils
"github.com/ipfs/go-ipfs/merkledag/utils"
"github.com/ipfs/go-ipfs/namesys"
path
"github.com/ipfs/go-ipfs/path"
ft
"github.com/ipfs/go-ipfs/unixfs"
...
...
@@ -169,26 +168,18 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
dir
:=
false
switch
err
{
case
nil
:
//
core.Resolve
worked
//
Cat()
worked
defer
dr
.
Close
()
case
coreiface
.
ErrIsDir
:
dir
=
true
case
namesys
.
ErrResolveFailed
:
// Don't log that error as it is just noise
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
fmt
.
Fprintf
(
w
,
"Path Resolve error: %s"
,
err
.
Error
())
log
.
Info
(
"Path Resolve error: %s"
,
err
.
Error
())
return
case
coreiface
.
ErrOffline
:
if
!
i
.
node
.
OnlineMode
()
{
w
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
fmt
.
Fprint
(
w
,
"Could not resolve path. Node is in offline mode."
)
webError
(
w
,
"ipfs cat "
+
urlPath
,
err
,
http
.
StatusServiceUnavailable
)
return
}
fallthrough
default
:
// all other erros
webError
(
w
,
"Path Resolve error"
,
err
,
http
.
StatusBadRequest
)
webError
(
w
,
"ipfs cat "
+
urlPath
,
err
,
http
.
StatusNotFound
)
return
}
...
...
@@ -532,7 +523,7 @@ func webErrorWithCode(w http.ResponseWriter, message string, err error, code int
w
.
WriteHeader
(
code
)
log
.
Errorf
(
"%s: %s"
,
message
,
err
)
// TODO(cryptix): log until we have a better way to expose these (counter metrics maybe)
fmt
.
Fprintf
(
w
,
"%s: %s"
,
message
,
err
)
fmt
.
Fprintf
(
w
,
"%s: %s
\n
"
,
message
,
err
)
}
// return a 500 error and log
...
...
core/corehttp/gateway_test.go
View file @
2cc5ce45
...
...
@@ -136,7 +136,7 @@ func TestGatewayGet(t *testing.T) {
{
"localhost:5001"
,
"/"
,
http
.
StatusNotFound
,
"404 page not found
\n
"
},
{
"localhost:5001"
,
"/"
+
k
,
http
.
StatusNotFound
,
"404 page not found
\n
"
},
{
"localhost:5001"
,
"/ipfs/"
+
k
,
http
.
StatusOK
,
"fnord"
},
{
"localhost:5001"
,
"/ipns/nxdomain.example.com"
,
http
.
Status
InternalServerError
,
"Path Resolve error
: "
+
namesys
.
ErrResolveFailed
.
Error
()},
{
"localhost:5001"
,
"/ipns/nxdomain.example.com"
,
http
.
Status
NotFound
,
"ipfs cat /ipns/nxdomain.example.com
: "
+
namesys
.
ErrResolveFailed
.
Error
()
+
"
\n
"
},
{
"localhost:5001"
,
"/ipns/example.com"
,
http
.
StatusOK
,
"fnord"
},
{
"example.com"
,
"/"
,
http
.
StatusOK
,
"fnord"
},
}
{
...
...
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