Class: RecipeScrapers::Http::BodyLimit
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- RecipeScrapers::Http::BodyLimit
- Defined in:
- lib/recipe_scrapers/http/body_limit.rb
Overview
Refuses a response larger than a limit, checked against Content-Length and against the body
itself. Registered as :recipe_scrapers_body_limit.
Instance Method Summary collapse
-
#initialize(app, bytes:) ⇒ BodyLimit
constructor
A new instance of BodyLimit.
- #on_complete(env) ⇒ Object private
Constructor Details
#initialize(app, bytes:) ⇒ BodyLimit
Returns a new instance of BodyLimit.
12 13 14 15 |
# File 'lib/recipe_scrapers/http/body_limit.rb', line 12 def initialize(app, bytes:) super(app) @bytes = bytes end |
Instance Method Details
#on_complete(env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 24 25 26 |
# File 'lib/recipe_scrapers/http/body_limit.rb', line 21 def on_complete(env) refuse(declared_size(env).to_i) if over_limit?(declared_size(env)) actual = env[:body].to_s.bytesize refuse(actual) if actual > @bytes end |