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
2d17fdf5
Unverified
Commit
2d17fdf5
authored
Apr 29, 2020
by
Steven Allen
Committed by
GitHub
Apr 29, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #195 from ipfs/fix/go-ipfs-7242
Fix go-ipfs#7242: Remove "HEAD" from Allow methods
parents
90c723d6
31eee8c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
http/errors_test.go
http/errors_test.go
+1
-1
http/handler.go
http/handler.go
+7
-7
No files found.
http/errors_test.go
View file @
2d17fdf5
...
...
@@ -165,7 +165,7 @@ func TestUnhandledMethod(t *testing.T) {
AllowGet
:
false
,
Code
:
http
.
StatusMethodNotAllowed
,
ResHeaders
:
map
[
string
]
string
{
"Allow"
:
"
POST, HEAD,
OPTIONS"
,
"Allow"
:
"OPTIONS
, POST
"
,
},
}
tc
.
test
(
t
)
...
...
http/handler.go
View file @
2d17fdf5
...
...
@@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"runtime/debug"
"strings"
"sync"
"time"
...
...
@@ -106,7 +107,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// The CORS library handles all other requests.
// Tell the user the allowed methods, and return.
setAllow
ed
Header
s
(
w
,
h
.
cfg
.
AllowGet
)
setAllowHeader
(
w
,
h
.
cfg
.
AllowGet
)
w
.
WriteHeader
(
http
.
StatusNoContent
)
return
case
http
.
MethodPost
:
...
...
@@ -116,7 +117,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
fallthrough
default
:
setAllow
ed
Header
s
(
w
,
h
.
cfg
.
AllowGet
)
setAllowHeader
(
w
,
h
.
cfg
.
AllowGet
)
http
.
Error
(
w
,
"405 - Method Not Allowed"
,
http
.
StatusMethodNotAllowed
)
log
.
Warnf
(
"The IPFS API does not support %s requests."
,
r
.
Method
)
return
...
...
@@ -191,11 +192,10 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h
.
root
.
Call
(
req
,
re
,
h
.
env
)
}
func
setAllowedHeaders
(
w
http
.
ResponseWriter
,
allowGet
bool
)
{
w
.
Header
()
.
Add
(
"Allow"
,
http
.
MethodHead
)
w
.
Header
()
.
Add
(
"Allow"
,
http
.
MethodOptions
)
w
.
Header
()
.
Add
(
"Allow"
,
http
.
MethodPost
)
func
setAllowHeader
(
w
http
.
ResponseWriter
,
allowGet
bool
)
{
allowedMethods
:=
[]
string
{
http
.
MethodOptions
,
http
.
MethodPost
}
if
allowGet
{
w
.
Header
()
.
Add
(
"Allow"
,
http
.
MethodGet
)
allowedMethods
=
append
(
allowedMethods
,
http
.
MethodHead
,
http
.
MethodGet
)
}
w
.
Header
()
.
Set
(
"Allow"
,
strings
.
Join
(
allowedMethods
,
", "
))
}
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