Class: Api2Convert::Http::Request
- Inherits:
-
Object
- Object
- Api2Convert::Http::Request
- Defined in:
- lib/api2convert/http/request.rb
Overview
A transport-agnostic HTTP request. The Transport builds these and hands them to an HttpSender; a retry rebuilds a fresh one so a seekable body is replayed from the start.
Exactly one of #body (a String) or #body_stream (an IO whose byte length is #content_length) is set on a request with a payload.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_stream ⇒ Object
readonly
Returns the value of attribute body_stream.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#follow_redirects ⇒ Object
Whether the sender may follow a 3xx redirect.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#response_sink ⇒ Object
readonly
Returns the value of attribute response_sink.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(method:, url:, headers: {}, body: nil, body_stream: nil, content_length: nil, follow_redirects: false, response_sink: nil) ⇒ Request
constructor
A new instance of Request.
-
#inspect ⇒ Object
Redacted representation — #headers carries the raw
X-Oc-Api-Key/X-Oc-Download-Passwordsecrets, so the default#inspectwould print them in cleartext in a log line or a backtrace. - #to_s ⇒ Object
Constructor Details
#initialize(method:, url:, headers: {}, body: nil, body_stream: nil, content_length: nil, follow_redirects: false, response_sink: nil) ⇒ Request
Returns a new instance of Request.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/api2convert/http/request.rb', line 18 def initialize(method:, url:, headers: {}, body: nil, body_stream: nil, content_length: nil, follow_redirects: false, response_sink: nil) @method = method.to_s.upcase @url = url @headers = headers @body = body @body_stream = body_stream @content_length = content_length @follow_redirects = follow_redirects # An IO-like object (responds to `write`) to stream a successful download # body into, instead of buffering it whole. nil for a normal request. @response_sink = response_sink end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def body @body end |
#body_stream ⇒ Object (readonly)
Returns the value of attribute body_stream.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def body_stream @body_stream end |
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def content_length @content_length end |
#follow_redirects ⇒ Object
Whether the sender may follow a 3xx redirect. Set by the transport per
request: authenticated requests carry a secret in a custom X-Oc-* header,
so they must NOT follow redirects (the header could leak to another host).
16 17 18 |
# File 'lib/api2convert/http/request.rb', line 16 def follow_redirects @follow_redirects end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def method @method end |
#response_sink ⇒ Object (readonly)
Returns the value of attribute response_sink.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def response_sink @response_sink end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/api2convert/http/request.rb', line 12 def url @url end |
Instance Method Details
#inspect ⇒ Object
Redacted representation — #headers carries the raw X-Oc-Api-Key /
X-Oc-Download-Password secrets, so the default #inspect would print
them in cleartext in a log line or a backtrace. Mask every X-Oc-* value.
35 36 37 38 39 40 |
# File 'lib/api2convert/http/request.rb', line 35 def inspect safe = @headers.to_h do |key, value| [key, key.to_s.downcase.start_with?("x-oc-") ? Support::Secret.mask(value) : value] end "#<#{self.class.name} method=#{@method.inspect} url=#{@url.inspect} headers=#{safe.inspect}>" end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/api2convert/http/request.rb', line 42 def to_s inspect end |