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
0b32f49e
Commit
0b32f49e
authored
Jul 24, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't set a Content-Type for empty responses in the REST API.
parent
3e50b558
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
74 deletions
+0
-74
handlers.go
pkg/rest/handlers.go
+0
-3
handlers_test.go
pkg/rest/handlers_test.go
+0
-71
No files found.
pkg/rest/handlers.go
View file @
0b32f49e
...
...
@@ -92,7 +92,6 @@ type healthzHndlr struct {
func
(
h
*
healthzHndlr
)
ServeHTTP
(
resp
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
now
:=
time
.
Now
()
resp
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
resp
.
Header
()
.
Set
(
"Content-Length"
,
"0"
)
resp
.
Header
()
.
Set
(
"Cache-Control"
,
"no-store"
)
status
:=
http
.
StatusTeapot
...
...
@@ -121,7 +120,6 @@ func (h *pemsHndlr) allPems(
req
*
http
.
Request
,
now
time
.
Time
,
)
{
resp
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
resp
.
Header
()
.
Set
(
"Content-Length"
,
"0"
)
resp
.
WriteHeader
(
http
.
StatusNotImplemented
)
reqLog
(
h
.
log
,
req
,
now
,
http
.
StatusNotImplemented
,
0
)
...
...
@@ -135,7 +133,6 @@ func (h *pemsHndlr) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
return
}
resp
.
Header
()
.
Set
(
"Content-Type"
,
"text/plain"
)
resp
.
Header
()
.
Set
(
"Content-Length"
,
"0"
)
status
:=
http
.
StatusTeapot
bytes
:=
0
...
...
pkg/rest/handlers_test.go
View file @
0b32f49e
...
...
@@ -69,12 +69,6 @@ func TestHealthz(t *testing.T) {
rr
.
Result
()
.
Header
.
Get
(
"Application-Version"
),
version
)
}
textPlain
:=
"text/plain"
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"GET /v1/healthz Content-Type: got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
noStore
:=
"no-store"
if
rr
.
Result
()
.
Header
.
Get
(
"Cache-Control"
)
!=
noStore
{
t
.
Errorf
(
"GET /v1/healthz Cache-Control: got %s want %s"
,
...
...
@@ -113,7 +107,6 @@ func TestHealthz405(t *testing.T) {
version
:
version
,
log
:
&
logrus
.
Logger
{
Out
:
ioutil
.
Discard
},
}
textPlain
:=
"text/plain"
noStore
:=
"no-store"
methods
:=
[]
string
{
...
...
@@ -134,11 +127,6 @@ func TestHealthz405(t *testing.T) {
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
))
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"%s /v1/healthz Content-Type: got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Cache-Control"
)
!=
noStore
{
t
.
Errorf
(
"%s /v1/healthz Cache-Control: got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Cache-Control"
),
...
...
@@ -327,13 +315,6 @@ func TestPutPem(t *testing.T) {
t
.
Errorf
(
"file contents after PUT: got %q want %q"
,
contents
,
expected
)
}
textPlain
:=
"text/plain"
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"PUT /v1/pems/ns1/secret1 Content-Type: "
+
"got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"PUT /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want 0"
,
...
...
@@ -347,12 +328,6 @@ func TestPutPem(t *testing.T) {
t
.
Errorf
(
"2nd PUT /v1/pems/ns1/secret1 status: got %d want %d"
,
rr
.
Code
,
http
.
StatusNoContent
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"PUT /v1/pems/ns1/secret1 Content-Type: "
+
"got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
""
{
t
.
Errorf
(
"2nd PUT /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want empty"
,
...
...
@@ -366,12 +341,6 @@ func TestPutPem(t *testing.T) {
t
.
Errorf
(
"PUT /v1/pems/foo/bar status: got %d want %d"
,
rr
.
Code
,
http
.
StatusNotFound
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"PUT /v1/pems/foo/bar Content-Type: "
+
"got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"PUT /v1/pems/foo/bar Content-Length: "
+
"got %s want 0"
,
...
...
@@ -580,13 +549,6 @@ func TestPostPem(t *testing.T) {
t
.
Errorf
(
"file contents after POST: got %q want %q"
,
contents
,
expected
)
}
textPlain
:=
"text/plain"
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"POST /v1/pems/ns1/secret1 Content-Type: "
+
"got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"POST /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want 0"
,
...
...
@@ -600,12 +562,6 @@ func TestPostPem(t *testing.T) {
t
.
Errorf
(
"2nd POST /v1/pems/ns1/secret1 status: got %d want %d"
,
rr
.
Code
,
http
.
StatusConflict
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"POST /v1/pems/ns1/secret1 Content-Type: "
+
"got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
"0"
{
t
.
Errorf
(
"2nd POST /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want 0"
,
...
...
@@ -678,13 +634,6 @@ func TestDeletePem(t *testing.T) {
if
files
.
Check
(
"ns1"
,
"secret1"
,
""
,
""
)
{
t
.
Error
(
"files.Check() after DELETE: got true want false"
)
}
textPlain
:=
"text/plain"
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"DELETE /v1/pems/ns1/secret1 Content-Type: "
+
"got %s want %s"
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
)
!=
""
{
t
.
Errorf
(
"DELETE /v1/pems/ns1/secret1 Content-Length: "
+
"got %s want empty"
,
...
...
@@ -756,7 +705,6 @@ func TestGetPem(t *testing.T) {
crtGetter
:
getter
,
}
textPlain
:=
"text/plain"
for
_
,
method
:=
range
[]
string
{
http
.
MethodGet
,
http
.
MethodHead
}
{
req
:=
httptest
.
NewRequest
(
method
,
"/v1/pems/ns/name"
,
nil
)
rr
:=
httptest
.
NewRecorder
()
...
...
@@ -770,12 +718,6 @@ func TestGetPem(t *testing.T) {
"got %s want 0"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
))
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"%s /v1/pems/ns/name Content-Type: "
+
"got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
}
}
...
...
@@ -799,7 +741,6 @@ func TestPem405(t *testing.T) {
crtGetter
:
getter
,
}
textPlain
:=
"text/plain"
methods
:=
[]
string
{
http
.
MethodPatch
,
http
.
MethodConnect
,
http
.
MethodOptions
,
http
.
MethodTrace
,
"BAZQUUX"
,
...
...
@@ -817,12 +758,6 @@ func TestPem405(t *testing.T) {
"got %s want 0"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
))
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"%s /v1/pems/ns/name Content-Type: "
+
"got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
}
}
...
...
@@ -846,7 +781,6 @@ func TestAllPem(t *testing.T) {
crtGetter
:
getter
,
}
textPlain
:=
"text/plain"
methods
:=
[]
string
{
http
.
MethodGet
,
http
.
MethodHead
,
http
.
MethodPost
,
http
.
MethodPut
,
http
.
MethodPatch
,
http
.
MethodDelete
,
...
...
@@ -867,10 +801,5 @@ func TestAllPem(t *testing.T) {
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Length"
))
}
if
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
)
!=
textPlain
{
t
.
Errorf
(
"%s /v1/pems Content-Type: got %s want %s"
,
method
,
rr
.
Result
()
.
Header
.
Get
(
"Content-Type"
),
textPlain
)
}
}
}
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