Class: ReactOnRailsPro::RendererHttpClient::Response
- Inherits:
-
Object
- Object
- ReactOnRailsPro::RendererHttpClient::Response
- Defined in:
- lib/react_on_rails_pro/renderer_http_client.rb,
sig/react_on_rails_pro/renderer_http_client.rbs
Overview
Not thread-safe. Each Response instance is owned and consumed by one renderer request path.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Integer?
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #body ⇒ String
- #each {|arg0| ... } ⇒ Object
- #error? ⇒ Boolean
-
#initialize(status: nil, body: nil, headers: nil, error: nil, &executor) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status: nil, body: nil, headers: nil, error: nil, &executor) ⇒ Response
Returns a new instance of Response.
340 341 342 343 344 345 346 347 348 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 340 def initialize(status: nil, body: nil, headers: nil, error: nil, &executor) @status = status @headers = normalize_headers(headers) @body_chunks = Array(body || []) @body = nil @error = error @executor = executor @consumed = false end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
338 339 340 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 338 def headers @headers end |
#status ⇒ Integer? (readonly)
Returns the value of attribute status.
338 339 340 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 338 def status @status end |
Instance Method Details
#body ⇒ String
350 351 352 353 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 350 def body consume unless @consumed @body ||= @body_chunks.join end |
#each ⇒ Enumerator[String, void] #each ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 360 def each(&block) return enum_for(:each) unless block if @executor && !@consumed consume(&block) else @body_chunks.each(&block) end # Replaying consumed chunks should still surface the stored response failure. raise @error if @error raise HTTPError, self if error? end |
#error? ⇒ Boolean
355 356 357 358 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 355 def error? # nil status means a lazy streaming executor has not run yet, so it is not-yet-an-error. !status.nil? && status >= 400 end |