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-cmds
Commits
6cc6af69
Unverified
Commit
6cc6af69
authored
May 24, 2019
by
Steven Allen
Committed by
GitHub
May 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #167 from ipfs/fix/http-errors
fix: use golang's http.Error to send errors
parents
1995f5cb
6978cc1e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
15 deletions
+7
-15
CODEOWNERS
CODEOWNERS
+0
-6
http/errors_test.go
http/errors_test.go
+1
-1
http/handler.go
http/handler.go
+6
-8
No files found.
CODEOWNERS
deleted
100644 → 0
View file @
1995f5cb
# Please see https://help.github.com/articles/about-codeowners/ for more information
# Global owner
* @keks
# Subsystem specific owners
http/errors_test.go
View file @
6cc6af69
...
...
@@ -92,7 +92,7 @@ func TestErrors(t *testing.T) {
cmds
.
EncLong
:
"foobar"
,
},
status
:
"400 Bad Request"
,
bodyStr
:
`
invalid encoding: foobar
`
,
bodyStr
:
"
invalid encoding: foobar
\n
"
,
},
{
...
...
http/handler.go
View file @
6cc6af69
...
...
@@ -96,8 +96,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}()
if
!
allowOrigin
(
r
,
h
.
cfg
)
||
!
allowReferer
(
r
,
h
.
cfg
)
{
w
.
WriteHeader
(
http
.
StatusForbidden
)
w
.
Write
([]
byte
(
"403 - Forbidden"
))
http
.
Error
(
w
,
"403 - Forbidden"
,
http
.
StatusForbidden
)
log
.
Warningf
(
"API blocked request to %s. (possible CSRF)"
,
r
.
URL
)
return
}
...
...
@@ -122,12 +121,12 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
req
,
err
:=
parseRequest
(
r
,
h
.
root
)
if
err
!=
nil
{
status
:=
http
.
StatusBadRequest
if
err
==
ErrNotFound
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
}
else
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
status
=
http
.
StatusNotFound
}
w
.
Write
([]
byte
(
err
.
Error
()))
http
.
Error
(
w
,
err
.
Error
(),
status
)
return
}
...
...
@@ -146,8 +145,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
re
,
err
:=
NewResponseEmitter
(
w
,
r
.
Method
,
req
,
withRequestBodyEOFChan
(
bodyEOFChan
))
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
w
.
Write
([]
byte
(
err
.
Error
()))
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
...
...
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