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.
397 398 399 400 401 402 403 404 405 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 397 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.
395 396 397 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 395 def headers @headers end |
#status ⇒ Integer? (readonly)
Returns the value of attribute status.
395 396 397 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 395 def status @status end |
Instance Method Details
#body ⇒ String
407 408 409 410 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 407 def body consume unless @consumed @body ||= @body_chunks.join end |
#each ⇒ Enumerator[String, void] #each ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 417 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
412 413 414 415 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 412 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 |