Skip to content

Per-Action maximum body size limits #1989

@jwoertink

Description

@jwoertink

We have a middleware for limiting your apps body request size https://github.com/luckyframework/lucky/blame/main/src/lucky/maximum_request_size_handler.cr

But this handler is expected to work on the whole app. If you set your app's limit to say 100mb because 1 API endpoint allows for it, then all the rest of them are still allowing 100mb. We should have a way to tune this at a per action base level.

For example, globally I want my app set to 1MB, but for 1 or 2 actions, I want to allow 25MB. Or maybe one allows 25MB and another allow 100MB.

The tricky part is this handler would sit before your route handler in the stack. So it wouldn't know which Action is going to be used until after it's already blocked the request. We probably just need a second module that works as an action pipe.

class Resumes::Create < ApiAction
  include Lucky::EnsureMaxBodySize

  # Some sort of method that tells how big in kb?
  set_body_size_limit 25000
end

module Lucky::EnsureMaxBodySize
  # adds that method in and includes
  # a before pipe to check it... maybe also checks Content-Length header?
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions