Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k8s-crt-dnldr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
k8s
k8s-crt-dnldr
Commits
b6cd2f4f
Commit
b6cd2f4f
authored
Jul 24, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set an Allow header in 405 responses.
parent
9fe1e308
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
handlers.go
pkg/rest/handlers.go
+5
-0
handlers_test.go
pkg/rest/handlers_test.go
+10
-0
No files found.
pkg/rest/handlers.go
View file @
b6cd2f4f
...
...
@@ -52,6 +52,8 @@ var (
http
.
MethodGet
:
struct
{}{},
http
.
MethodHead
:
struct
{}{},
}
allowHealthz
=
"GET, HEAD"
allowedPems
=
map
[
string
]
struct
{}{
http
.
MethodGet
:
struct
{}{},
http
.
MethodHead
:
struct
{}{},
...
...
@@ -59,6 +61,7 @@ var (
http
.
MethodPost
:
struct
{}{},
http
.
MethodPut
:
struct
{}{},
}
allowPems
=
"GET, HEAD, PUT, POST, DELETE"
)
// Date format for Common Log Format
...
...
@@ -100,6 +103,7 @@ func (h *healthzHndlr) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
status
=
http
.
StatusNotFound
}
else
if
_
,
ok
:=
allowedHealthz
[
req
.
Method
];
!
ok
{
status
=
http
.
StatusMethodNotAllowed
resp
.
Header
()
.
Set
(
"Allow"
,
allowHealthz
)
}
else
{
status
=
http
.
StatusNoContent
resp
.
Header
()
.
Del
(
"Content-Length"
)
...
...
@@ -147,6 +151,7 @@ func (h *pemsHndlr) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
if
_
,
ok
:=
allowedPems
[
req
.
Method
];
!
ok
{
status
=
http
.
StatusMethodNotAllowed
resp
.
Header
()
.
Set
(
"Allow"
,
allowPems
)
resp
.
WriteHeader
(
status
)
reqLog
(
h
.
log
,
req
,
now
,
status
,
bytes
)
return
...
...
pkg/rest/handlers_test.go
View file @
b6cd2f4f
...
...
@@ -122,6 +122,11 @@ func TestHealthz405(t *testing.T) {
t
.
Errorf
(
"%s /v1/healthz status: got %d want %d"
,
method
,
rr
.
Code
,
http
.
StatusMethodNotAllowed
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Allow"
)
!=
allowHealthz
{
t
.
Errorf
(
"%s /v1/healthz Allow: got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Allow"
),
allowHealthz
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"%s /v1/healthz Content-Length: got %s want 0"
,
method
,
rr
.
Result
()
.
Header
.
...
...
@@ -753,6 +758,11 @@ func TestPem405(t *testing.T) {
t
.
Errorf
(
"%s /v1/pems/ns/name status: got %d want %d"
,
method
,
rr
.
Code
,
http
.
StatusMethodNotAllowed
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Allow"
)
!=
allowPems
{
t
.
Errorf
(
"%s /v1/pems/ns/name Allow: got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Allow"
),
allowPems
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"%s /v1/pems/ns/name Content-Length: "
+
"got %s want 0"
,
method
,
...
...
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