-
Notifications
You must be signed in to change notification settings - Fork 407
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
pkg/server/api: Return 405s for non-GET requests #240
pkg/server/api: Return 405s for non-GET requests #240
Conversation
Can you add tests to |
/hold |
Each sub-handler would be switching on Path anyway, and we don't have so many paths for the muxer's extra level of path switching to help much. And it's nice to only have to put things like [1]'s method guard in one spot (vs. repeating in each of the muxer's sub-handlers). [1]: openshift#240
a9e8294
to
98d3fa2
Compare
Rebased onto #242 and added a test with a9e8294 -> 98d3fa2. |
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.
👍
98d3fa2
to
2dc59a3
Compare
With #242 closed, I've rebased this onto master again and added a unit test based on |
/hold cancel |
James is working on getting that limit bumped, but until then it's just luck ;). I'll wait until the queue calms down tonight before retesting, since this is a fairly minor change. |
Our limit has been bumped. /retest |
2dc59a3
to
22d0c45
Compare
@@ -80,8 +80,14 @@ func NewServerAPIHandler(s Server) *APIHandler { | |||
// ServeHTTP handles the requests for the machine config server | |||
// API handler. | |||
func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
if r.Method != http.MethodGet && r.Method != http.MethodHead { | |||
w.Header().Set("Content-Length", "0") |
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.
Can you point to to a reason why we need to set this?
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.
Can you point to to a reason why we need to set this?
If people start HEAD
ing this server, it seems like they might be interested in getting valid Content-Length
back. I just started setting it everywhere to make it easier to test that we get it right when we actually care about it.
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.
So looking at 5f0a6a7
The defaultHandler gives us our usual empty 404s for requests that
don't match our other handlers. Without it, we'd have returned Go's
default:
404 page not found
body, and had unit-test failures like:
--- FAIL: TestHandler (0.00s)
--- FAIL: TestHandler/GET_/does-not-exist (0.00s)
api_test.go:93: response body length 19 does not match Content-Length -1
I makes me go back to to the original thing that we should not setting/expecting Content-Length
when we only care about the StatusCode.
So maybe can we remove all the w.Header().Set("Content-Length", "0")
and only set it when we care, ie HEAD/GET success result.
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.
It makes me go back to to the original thing that we should not setting/expecting
Content-Length
when we only care about the StatusCode.
If we want to return 404 page not found\n
(with Content-Type: text/plain; charset=utf-8
?) for all of our 404s, I'm ok with that (although I don't see a need to do it). But I would like to be consistent among our 404s, and not have some that return with no body and some that return with the text/plain body.
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.
lets keep it as is for now..
images failure was openshift/release#2070. /retest |
0eebfed
to
124fd90
Compare
We don't want folks POSTing, etc. to this server. If they do, this commit will return the appropriate response status code. Also add support for HEAD requests and start setting Content-Length and Content-Type ourselves instead of leaning on Go's autodetection [1]. The application/json media type is from [2]. [1]: https://golang.org/pkg/net/http/#ResponseWriter [2]: https://tools.ietf.org/html/rfc8259#section-1.2
124fd90
to
01d22e1
Compare
/lgtm /retest |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abhinavdahiya, wking 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 |
/test e2e-aws |
/retest Please review the full test history for this PR and help us cut down flakes. |
…streams-from-progressing Bug 1811143: purge removed imagestreams as a part of upgrade from progessing/impor…
We don't want folks
POST
ing, etc. to this server. With this pull-request, we'll return the appropriate response status code if they do.