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

Adding a MaximumRequestSizeHandler #1916

Merged
merged 6 commits into from
Oct 9, 2024

Conversation

russ
Copy link
Contributor

@russ russ commented Oct 6, 2024

  • Configurable to be on/off. Off by default.
  • Configurable to set the maximum request size. Default is 1MB.

Purpose

A configurable handler for setting a maximum size on requests.

Description

Fixes #1143

Checklist

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

* Configurable to be on/off. Off by default.
* Configurable to set the maximum request size. Default is 1MB.

Ref luckyframework#1143
@russ
Copy link
Contributor Author

russ commented Oct 6, 2024

Where should docs for this go?

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

From what I can tell, this seems like it's fine. I'm not sure why the specs are failing on it though. As for docs, either at the top of the class file just above the class definition, or we just write them up on the website.

Lucky::MaximumRequestSizeHandler.temp_config(enabled: true) do
run_request_size_handler(context)
end
context.response.status.should eq(HTTP::Status::PAYLOAD_TOO_LARGE)
Copy link
Member

Choose a reason for hiding this comment

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

seems this failed?

spec/spec_helper.cr Outdated Show resolved Hide resolved

Habitat.create do
setting enabled : Bool = false
setting max_size : Int32 = 1_048_576 # 1MB
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

actually... if you wanted this to be say 10GB (video uploads), would this need to be Int64?

@jwoertink jwoertink added the hacktoberfest-accepted PRs accepted for Hacktoberfest label Oct 7, 2024
Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

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

I think the failure is related to changes in ExceptionPage and probably unrelated. The rest looks good! Thanks 🙌

@jwoertink jwoertink merged commit ff1bebd into luckyframework:main Oct 9, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted PRs accepted for Hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have maximum request size by default
2 participants