Skip to content

Instantly share code, notes, and snippets.

@mtodd
Created September 16, 2008 20:13
Show Gist options
  • Save mtodd/11125 to your computer and use it in GitHub Desktop.
Save mtodd/11125 to your computer and use it in GitHub Desktop.
class LimitPostBodySize
attr_accessor :app, :max_size
def initialize(app, max_size); @app, @max_size = app, max_size; end
def call(env)
if env['rack.input'].stat.size < @max_size
@app.call(env)
else
[413, {'Content-Type' => 'text/plain'}, 'Request Entity Too Large']
end
end
end
use LimitPostBodySize, 4096 # 4k is reasonable
run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment