Class: Html2rss::RequestService::ResponseGuard
- Inherits:
-
Object
- Object
- Html2rss::RequestService::ResponseGuard
- Defined in:
- lib/html2rss/request_service/response_guard.rb
Overview
Enforces response-size limits before parsing.
Instance Method Summary collapse
-
#initialize(policy:) ⇒ ResponseGuard
constructor
A new instance of ResponseGuard.
-
#inspect_body!(body) ⇒ void
Validates the final response body after middleware processing.
-
#inspect_chunk!(total_bytes:, headers: nil) ⇒ void
Validates response headers and streamed byte count.
Constructor Details
#initialize(policy:) ⇒ ResponseGuard
Returns a new instance of ResponseGuard.
10 11 12 13 |
# File 'lib/html2rss/request_service/response_guard.rb', line 10 def initialize(policy:) @policy = policy @streamed_bytes = 0 end |
Instance Method Details
#inspect_body!(body) ⇒ void
This method returns an undefined value.
Validates the final response body after middleware processing.
37 38 39 40 41 42 |
# File 'lib/html2rss/request_service/response_guard.rb', line 37 def inspect_body!(body) normalized_body = body.to_s size = normalized_body.bytesize raise_if_too_large!(size, policy.max_decompressed_bytes) raise_if_blocked_surface!(normalized_body) end |
#inspect_chunk!(total_bytes:, headers: nil) ⇒ void
This method returns an undefined value.
Validates response headers and streamed byte count.
22 23 24 25 26 27 28 |
# File 'lib/html2rss/request_service/response_guard.rb', line 22 def inspect_chunk!(total_bytes:, headers: nil) header_length = headers&.fetch('content-length', headers&.fetch('Content-Length', nil)) raise_if_too_large!(header_length.to_i, policy.max_response_bytes) if header_length @streamed_bytes = total_bytes raise_if_too_large!(@streamed_bytes, policy.max_response_bytes) end |