Skip to content

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

Merged
VojtechVitek merged 1 commit into
go-chi:masterfrom
GocaMaric:patch-1
Sep 18, 2024
Merged

Support Content-Type headers with charset/boundary parameters#880
VojtechVitek merged 1 commit into
go-chi:masterfrom
GocaMaric:patch-1

Conversation

@GocaMaric

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Changed the function parameters, code formatting and inline function.

Comment thread middleware/content_type.go

@VojtechVitek VojtechVitek left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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!

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