Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
2fb3ba71
Unverified
Commit
2fb3ba71
authored
Oct 08, 2018
by
Ibrahim AshShohail
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update usages of http.ResponseWriter.WriteHeader to use http.Error
Signed-off-by:
Ibrahim AshShohail
<
me@ibrasho.com
>
parent
add731df
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
29 additions
and
32 deletions
+29
-32
markmaster_test.go
cmd/kubeadm/app/phases/markmaster/markmaster_test.go
+2
-2
endpoints_controller_test.go
pkg/controller/endpoint/endpoints_controller_test.go
+1
-1
dump.go
pkg/controller/garbagecollector/dump.go
+2
-3
metadata_test.go
pkg/credentialprovider/gcp/metadata_test.go
+7
-7
proxy_server.go
pkg/kubectl/proxy/proxy_server.go
+1
-2
httpstream.go
pkg/kubelet/server/remotecommand/httpstream.go
+1
-2
http_test.go
pkg/probe/http/http_test.go
+1
-1
httpstream.go
...src/k8s.io/apimachinery/pkg/util/httpstream/httpstream.go
+3
-3
upgrade.go
...c/k8s.io/apimachinery/pkg/util/httpstream/spdy/upgrade.go
+4
-4
authn_audit_test.go
...8s.io/apiserver/pkg/endpoints/filters/authn_audit_test.go
+4
-4
maxinflight.go
...ng/src/k8s.io/apiserver/pkg/server/filters/maxinflight.go
+2
-2
etcd_util_test.go
.../k8s.io/apiserver/pkg/storage/etcd/util/etcd_util_test.go
+1
-1
No files found.
cmd/kubeadm/app/phases/markmaster/markmaster_test.go
View file @
2fb3ba71
...
...
@@ -140,7 +140,7 @@ func TestMarkMaster(t *testing.T) {
if
req
.
URL
.
Path
!=
"/api/v1/nodes/"
+
hostname
{
t
.
Errorf
(
"MarkMaster(%s): request for unexpected HTTP resource: %v"
,
tc
.
name
,
req
.
URL
.
Path
)
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
return
}
...
...
@@ -150,7 +150,7 @@ func TestMarkMaster(t *testing.T) {
patchRequest
=
toString
(
req
.
Body
)
default
:
t
.
Errorf
(
"MarkMaster(%s): request for unexpected HTTP verb: %v"
,
tc
.
name
,
req
.
Method
)
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
return
}
...
...
pkg/controller/endpoint/endpoints_controller_test.go
View file @
2fb3ba71
...
...
@@ -120,7 +120,7 @@ func makeTestServer(t *testing.T, namespace string) (*httptest.Server, *utiltest
mux
.
Handle
(
testapi
.
Default
.
ResourcePath
(
"endpoints/"
,
namespace
,
""
),
&
fakeEndpointsHandler
)
mux
.
HandleFunc
(
"/"
,
func
(
res
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
t
.
Errorf
(
"unexpected request: %v"
,
req
.
RequestURI
)
res
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
res
,
""
,
http
.
StatusNotFound
)
})
return
httptest
.
NewServer
(
mux
),
&
fakeEndpointsHandler
}
...
...
pkg/controller/garbagecollector/dump.go
View file @
2fb3ba71
...
...
@@ -252,7 +252,7 @@ type debugHTTPHandler struct {
func
(
h
*
debugHTTPHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
if
req
.
URL
.
Path
!=
"/graph"
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
return
}
...
...
@@ -270,8 +270,7 @@ func (h *debugHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
data
,
err
:=
dot
.
Marshal
(
graph
,
"full"
,
""
,
" "
,
false
)
if
err
!=
nil
{
w
.
Write
([]
byte
(
err
.
Error
()))
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
w
.
Write
(
data
)
...
...
pkg/credentialprovider/gcp/metadata_test.go
View file @
2fb3ba71
...
...
@@ -70,7 +70,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadata(t *testing.T) {
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
fmt
.
Fprintln
(
w
,
sampleDockerConfig
)
}
else
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}
}))
defer
server
.
Close
()
...
...
@@ -148,7 +148,7 @@ func TestDockerKeyringFromGoogleDockerConfigMetadataUrl(t *testing.T) {
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/text"
)
fmt
.
Fprint
(
w
,
"http://foo.bar.com"
+
valueEndpoint
)
}
else
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}
}))
defer
server
.
Close
()
...
...
@@ -232,7 +232,7 @@ func TestContainerRegistryBasics(t *testing.T) {
w
.
WriteHeader
(
http
.
StatusOK
)
fmt
.
Fprintln
(
w
,
"default/
\n
custom"
)
}
else
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}
}))
defer
server
.
Close
()
...
...
@@ -291,7 +291,7 @@ func TestContainerRegistryNoServiceAccount(t *testing.T) {
}
fmt
.
Fprintln
(
w
,
string
(
bytes
))
}
else
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}
}))
defer
server
.
Close
()
...
...
@@ -335,7 +335,7 @@ func TestContainerRegistryNoStorageScope(t *testing.T) {
w
.
WriteHeader
(
http
.
StatusOK
)
fmt
.
Fprintln
(
w
,
"default/
\n
custom"
)
}
else
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}
}))
defer
server
.
Close
()
...
...
@@ -380,7 +380,7 @@ func TestComputePlatformScopeSubstitutesStorageScope(t *testing.T) {
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
fmt
.
Fprintln
(
w
,
"default/
\n
custom"
)
}
else
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}
}))
defer
server
.
Close
()
...
...
@@ -410,7 +410,7 @@ func TestComputePlatformScopeSubstitutesStorageScope(t *testing.T) {
func
TestAllProvidersNoMetadata
(
t
*
testing
.
T
)
{
server
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusNotFound
)
http
.
Error
(
w
,
""
,
http
.
StatusNotFound
)
}))
defer
server
.
Close
()
...
...
pkg/kubectl/proxy/proxy_server.go
View file @
2fb3ba71
...
...
@@ -140,8 +140,7 @@ func (f *FilterServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
return
}
glog
.
V
(
3
)
.
Infof
(
"Filter rejecting %v %v %v"
,
req
.
Method
,
req
.
URL
.
Path
,
host
)
rw
.
WriteHeader
(
http
.
StatusForbidden
)
rw
.
Write
([]
byte
(
"<h3>Unauthorized</h3>"
))
http
.
Error
(
rw
,
http
.
StatusText
(
http
.
StatusForbidden
),
http
.
StatusForbidden
)
}
// Server is a http.Handler which proxies Kubernetes APIs to remote API server.
...
...
pkg/kubelet/server/remotecommand/httpstream.go
View file @
2fb3ba71
...
...
@@ -125,8 +125,7 @@ func createStreams(req *http.Request, w http.ResponseWriter, opts *Options, supp
func
createHttpStreamStreams
(
req
*
http
.
Request
,
w
http
.
ResponseWriter
,
opts
*
Options
,
supportedStreamProtocols
[]
string
,
idleTimeout
,
streamCreationTimeout
time
.
Duration
)
(
*
context
,
bool
)
{
protocol
,
err
:=
httpstream
.
Handshake
(
req
,
w
,
supportedStreamProtocols
)
if
err
!=
nil
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
fmt
.
Fprint
(
w
,
err
.
Error
())
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
nil
,
false
}
...
...
pkg/probe/http/http_test.go
View file @
2fb3ba71
...
...
@@ -57,7 +57,7 @@ func TestHTTPProbeChecker(t *testing.T) {
if
r
.
URL
.
Path
==
"/"
{
http
.
Redirect
(
w
,
r
,
"/new"
,
s
)
}
else
if
bad
&&
r
.
URL
.
Path
==
"/new"
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
""
,
http
.
StatusInternalServerError
)
}
}
}
...
...
staging/src/k8s.io/apimachinery/pkg/util/httpstream/httpstream.go
View file @
2fb3ba71
...
...
@@ -136,12 +136,12 @@ func Handshake(req *http.Request, w http.ResponseWriter, serverProtocols []strin
negotiatedProtocol
:=
negotiateProtocol
(
clientProtocols
,
serverProtocols
)
if
len
(
negotiatedProtocol
)
==
0
{
w
.
WriteHeader
(
http
.
StatusForbidden
)
for
i
:=
range
serverProtocols
{
w
.
Header
()
.
Add
(
HeaderAcceptedProtocolVersions
,
serverProtocols
[
i
])
}
fmt
.
Fprintf
(
w
,
"unable to upgrade: unable to negotiate protocol: client supports %v, server accepts %v"
,
clientProtocols
,
serverProtocols
)
return
""
,
fmt
.
Errorf
(
"unable to upgrade: unable to negotiate protocol: client supports %v, server supports %v"
,
clientProtocols
,
serverProtocols
)
err
:=
fmt
.
Errorf
(
"unable to upgrade: unable to negotiate protocol: client supports %v, server accepts %v"
,
clientProtocols
,
serverProtocols
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusForbidden
)
return
""
,
err
}
w
.
Header
()
.
Add
(
HeaderProtocolVersion
,
negotiatedProtocol
)
...
...
staging/src/k8s.io/apimachinery/pkg/util/httpstream/spdy/upgrade.go
View file @
2fb3ba71
...
...
@@ -74,15 +74,15 @@ func (u responseUpgrader) UpgradeResponse(w http.ResponseWriter, req *http.Reque
connectionHeader
:=
strings
.
ToLower
(
req
.
Header
.
Get
(
httpstream
.
HeaderConnection
))
upgradeHeader
:=
strings
.
ToLower
(
req
.
Header
.
Get
(
httpstream
.
HeaderUpgrade
))
if
!
strings
.
Contains
(
connectionHeader
,
strings
.
ToLower
(
httpstream
.
HeaderUpgrade
))
||
!
strings
.
Contains
(
upgradeHeader
,
strings
.
ToLower
(
HeaderSpdy31
))
{
w
.
WriteHeader
(
http
.
StatusBadRequest
)
fmt
.
Fprintf
(
w
,
"unable to upgrade: missing upgrade headers in request: %#v"
,
req
.
Header
)
errorMsg
:=
fmt
.
Sprintf
(
"unable to upgrade: missing upgrade headers in request: %#v"
,
req
.
Header
)
http
.
Error
(
w
,
errorMsg
,
http
.
StatusBadRequest
)
return
nil
}
hijacker
,
ok
:=
w
.
(
http
.
Hijacker
)
if
!
ok
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
fmt
.
Fprintf
(
w
,
"unable to upgrade: unable to hijack response"
)
errorMsg
:=
fmt
.
Sprintf
(
"unable to upgrade: unable to hijack response"
)
http
.
Error
(
w
,
errorMsg
,
http
.
StatusInternalServerError
)
return
nil
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/filters/authn_audit_test.go
View file @
2fb3ba71
...
...
@@ -33,7 +33,7 @@ func TestFailedAuthnAudit(t *testing.T) {
policyChecker
:=
policy
.
FakeChecker
(
auditinternal
.
LevelRequestResponse
,
nil
)
handler
:=
WithFailedAuthenticationAudit
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
http
.
Error
(
w
,
""
,
http
.
StatusUnauthorized
)
}),
sink
,
policyChecker
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/v1/namespaces/default/pods"
,
nil
)
...
...
@@ -65,7 +65,7 @@ func TestFailedMultipleAuthnAudit(t *testing.T) {
policyChecker
:=
policy
.
FakeChecker
(
auditinternal
.
LevelRequestResponse
,
nil
)
handler
:=
WithFailedAuthenticationAudit
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
http
.
Error
(
w
,
""
,
http
.
StatusUnauthorized
)
}),
sink
,
policyChecker
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/v1/namespaces/default/pods"
,
nil
)
...
...
@@ -98,7 +98,7 @@ func TestFailedAuthnAuditWithoutAuthorization(t *testing.T) {
policyChecker
:=
policy
.
FakeChecker
(
auditinternal
.
LevelRequestResponse
,
nil
)
handler
:=
WithFailedAuthenticationAudit
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
http
.
Error
(
w
,
""
,
http
.
StatusUnauthorized
)
}),
sink
,
policyChecker
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/v1/namespaces/default/pods"
,
nil
)
...
...
@@ -129,7 +129,7 @@ func TestFailedAuthnAuditOmitted(t *testing.T) {
policyChecker
:=
policy
.
FakeChecker
(
auditinternal
.
LevelRequestResponse
,
[]
auditinternal
.
Stage
{
auditinternal
.
StageResponseStarted
})
handler
:=
WithFailedAuthenticationAudit
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
http
.
Error
(
w
,
""
,
http
.
StatusUnauthorized
)
}),
sink
,
policyChecker
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/v1/namespaces/default/pods"
,
nil
)
...
...
staging/src/k8s.io/apiserver/pkg/server/filters/maxinflight.go
View file @
2fb3ba71
...
...
@@ -45,8 +45,8 @@ const (
var
nonMutatingRequestVerbs
=
sets
.
NewString
(
"get"
,
"list"
,
"watch"
)
func
handleError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
error
)
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
fmt
.
Fprintf
(
w
,
"Internal Server Error: %#v"
,
r
.
RequestURI
)
errorMsg
:=
fmt
.
Sprintf
(
"Internal Server Error: %#v"
,
r
.
RequestURI
)
http
.
Error
(
w
,
errorMsg
,
http
.
StatusInternalServerError
)
glog
.
Errorf
(
err
.
Error
())
}
...
...
staging/src/k8s.io/apiserver/pkg/storage/etcd/util/etcd_util_test.go
View file @
2fb3ba71
...
...
@@ -60,7 +60,7 @@ func TestGetEtcdVersion_ValidVersion(t *testing.T) {
func
TestGetEtcdVersion_ErrorStatus
(
t
*
testing
.
T
)
{
testServer
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
http
.
Error
(
w
,
""
,
http
.
StatusServiceUnavailable
)
}))
defer
testServer
.
Close
()
...
...
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