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

Request size middleware #809

Merged
merged 1 commit into from
Mar 31, 2023
Merged

Request size middleware #809

merged 1 commit into from
Mar 31, 2023

Conversation

farazfazli
Copy link
Contributor

Adds the middleware discussed in #808.

@farazfazli farazfazli changed the title Request size middleware (#808) Request size middleware Mar 31, 2023
@pkieltyka
Copy link
Member

Nice

@pkieltyka pkieltyka merged commit fd8a51e into go-chi:master Mar 31, 2023
func RequestSize(bytes int64) func(http.Handler) http.Handler {
f := func(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, bytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

@pkieltyka @farazfazli Do you think we could also error out (HTTP 4xx) early if r.ContentLength > bytes ?

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.

3 participants