-
Notifications
You must be signed in to change notification settings - Fork 4
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
code suggestion #25
code suggestion #25
Conversation
ccoVeille
commented
Dec 8, 2024
•
edited
Loading
edited
- chore: fix acronyms
- chore: use tb variable for testing.TB
- fix: potential Slowloris Attack
- refactor: restore the context, do not create one
- fix: use the expect Content-Type for OpenAPI
- chore: remove useless variables
- chore: rename method and variable to comply the acronym
- chore: use http constant
- test: fix inverted got-want
- test: make sure to close res.Body
- test: make sure to context is cancelled
- refactor: simplify panic recovery
- refactor: use type assertion and errors.Is to validate the server aborted
- refactor: do not use sprintf when sprint can be used
- refactor: invert if statement to make it clearer
this prevents to lose everything stored in the context
os.Exit called in TestMain will stop everything, defers are not launched
10351fe
to
5ead8d5
Compare
I applied the requested changes and suggestions |
func handleGetOpenAPI(version string) http.HandlerFunc { | ||
body := bytes.Replace(openAPI, []byte("${{ VERSION }}"), []byte(version), 1) | ||
return func(w http.ResponseWriter, _ *http.Request) { | ||
w.Header().Set("Content-Type", "text/yaml") |
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.
w.Header().Set("Content-Type", "text/yaml") | |
w.Header().Set("Content-Type", "application/yaml") |
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'm too tired, indeed
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 type is not official, i'll fix it and merge this pr
t.Parallel() | ||
res, err := http.Get(endpoint + "/openapi.yaml") | ||
testNil(t, err) | ||
testEqual(t, http.StatusOK, res.StatusCode) | ||
testEqual(t, "text/plain", res.Header.Get("Content-Type")) | ||
testEqual(t, "text/yaml", res.Header.Get("Content-Type")) |
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.
testEqual(t, "text/yaml", res.Header.Get("Content-Type")) | |
testEqual(t, "application/yaml", res.Header.Get("Content-Type")) |
Thanks for detailed contribution! Handling panic this way is much cleaner and safe. |