-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update usages of http.ResponseWriter.WriteHeader to use http.Error #69013
Update usages of http.ResponseWriter.WriteHeader to use http.Error #69013
Conversation
@ibrasho /ok-to-test |
please run (and commit) |
217d7db
to
448c878
Compare
5530727
to
e412cba
Compare
Seems like the failures were flakes. |
e412cba
to
51f070e
Compare
/lgtm Thanks! |
pkg/proxy/healthcheck/healthcheck.go
Outdated
@@ -211,7 +211,7 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { | |||
|
|||
resp.Header().Set("Content-Type", "application/json") | |||
if count == 0 { | |||
resp.WriteHeader(http.StatusServiceUnavailable) | |||
http.Error(resp, "", http.StatusServiceUnavailable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this resets the content type and makes the following json an invalid response, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localEndpoints
will be equal to 0 in case of an error. Is that the right behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localEndpoints will be equal to 0 in case of an error. Is that the right behavior?
that would be a good question for @kubernetes/sig-network-api-reviews, but my leaning would be toward keeping the current behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR to keep the current behavior here.
pkg/proxy/healthcheck/healthcheck.go
Outdated
@@ -339,7 +339,7 @@ func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { | |||
|
|||
resp.Header().Set("Content-Type", "application/json") | |||
if !lastUpdated.IsZero() && currentTime.After(lastUpdated.Add(h.hs.healthTimeout)) { | |||
resp.WriteHeader(http.StatusServiceUnavailable) | |||
http.Error(resp, "", http.StatusServiceUnavailable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, we shouldn't send json after resetting to text/plain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here. In case of an error, does the current response make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will defer to @kubernetes/sig-network-api-reviews as well, or we can restore current behavior and work through a change here in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR to keep the current behavior here.
/lgtm cancel |
51f070e
to
039e0fa
Compare
I've updated the PR to keep the current behavior in |
039e0fa
to
31a6f85
Compare
Signed-off-by: Ibrahim AshShohail <me@ibrasho.com>
31a6f85
to
2fb3ba7
Compare
/lgtm |
BTW, top-level |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ibrasho, liggitt, smarterclayton The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Replaces most usages of
http.ResponseWrite.WriteHeader
withhttp.Error
to ensureContent-Type
andX-Content-Type-Options
headers are set.Which issue(s) this PR fixes
fixes #69011
Special notes for your reviewer:
Release note: