Skip to content
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

Merged
merged 15 commits into from
Dec 9, 2024
Merged

code suggestion #25

merged 15 commits into from
Dec 9, 2024

Conversation

ccoVeille
Copy link
Contributor

@ccoVeille ccoVeille commented Dec 8, 2024

  • 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

@raeperd raeperd self-requested a review December 9, 2024 02:44
main.go Outdated Show resolved Hide resolved
main_test.go Outdated Show resolved Hide resolved
main_test.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main_test.go Outdated Show resolved Hide resolved
@raeperd raeperd added the enhancement New feature or request label Dec 9, 2024
@ccoVeille
Copy link
Contributor Author

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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
w.Header().Set("Content-Type", "text/yaml")
w.Header().Set("Content-Type", "application/yaml")

Copy link
Contributor Author

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

Copy link
Owner

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"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testEqual(t, "text/yaml", res.Header.Get("Content-Type"))
testEqual(t, "application/yaml", res.Header.Get("Content-Type"))

@raeperd
Copy link
Owner

raeperd commented Dec 9, 2024

Thanks for detailed contribution!

Handling panic this way is much cleaner and safe.
Sorry if it seems like I'm being overly critical during the code review.
Merge this pr.

@raeperd raeperd merged commit c7ae46e into raeperd:main Dec 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants