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

Support Content-Type headers with charset/boundary parameters #880

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

GocaMaric
Copy link
Contributor

Handler Function Parameters: Changed the function parameters of the returned handler functions to use the http.Handler interface directly. This makes the code more idiomatic and allows for better compatibility with other middleware.

Inline Function Definitions: Eliminated the need for the intermediate fn variable in both SetHeader and AllowContentType functions. You can directly return the http.HandlerFunc in a more concise manner.

Code Comments: Added a comment to explain the splitting of the content type string to extract the MIME type. This improves code readability.

Code Formatting: Applied consistent code formatting to improve readability.

@GocaMaric
Copy link
Contributor Author

Changed the function parameters, code formatting and inline function.

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution :)

@VojtechVitek VojtechVitek changed the title Update content_type.go Support Content-Type headers with charset/boundary parameters Sep 18, 2024
if i := strings.Index(s, ";"); i > -1 {
s = s[0:i]
}
s := strings.ToLower(strings.TrimSpace(strings.Split(r.Header.Get("Content-Type"), ";")[0]))
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't change the behavior (much).

The code is slightly cleaner and can trim whitespaces within first part of the header value.

I'll merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I agree that trimming whitespaces and cleaning up the code makes it more efficient and readable. Appreciate you merging the changes!

@VojtechVitek VojtechVitek merged commit 882c15e into go-chi:master Sep 18, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants