Class: VCR::Request
- Inherits:
-
Struct
- Object
- Struct
- VCR::Request
- Includes:
- Normalizers::Body, Normalizers::Header
- Defined in:
- lib/vcr/structs.rb
Overview
The request of an HTTPInteraction.
Defined Under Namespace
Classes: FiberAware, Typed
Constant Summary collapse
- @@object_method =
Object.instance_method(:method)
Instance Attribute Summary collapse
-
#body ⇒ String?
the request body.
-
#headers ⇒ Hash{String => Array<String>}
the request headers.
-
#method(*args) ⇒ Symbol
the HTTP method (i.e. :head, :options, :get, :post, :put, :patch or :delete).
-
#uri ⇒ String
the request URI.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Request
Constructs a new instance from a hash.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Request
constructor
A new instance of Request.
-
#parsed_uri ⇒ #schema, ...
Parses the URI using the configured ‘uri_parser`.
-
#to_hash ⇒ Hash
Builds a serializable hash from the request data.
Methods included from Normalizers::Body
Constructor Details
#initialize(*args) ⇒ Request
Returns a new instance of Request.
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/vcr/structs.rb', line 199 def initialize(*args) skip_port_stripping = false if args.last == :skip_port_stripping skip_port_stripping = true args.pop end super(*args) self.method = self.method.to_s.downcase.to_sym if self.method self.uri = without_standard_port(self.uri) unless skip_port_stripping end |
Instance Attribute Details
#body ⇒ String?
the request body
195 196 197 |
# File 'lib/vcr/structs.rb', line 195 def body @body end |
#headers ⇒ Hash{String => Array<String>}
the request headers
195 196 197 |
# File 'lib/vcr/structs.rb', line 195 def headers @headers end |
#method(*args) ⇒ Symbol
the HTTP method (i.e. :head, :options, :get, :post, :put, :patch or :delete)
195 196 197 |
# File 'lib/vcr/structs.rb', line 195 def method @method end |
#uri ⇒ String
the request URI
195 196 197 |
# File 'lib/vcr/structs.rb', line 195 def uri @uri end |
Class Method Details
.from_hash(hash) ⇒ Request
Constructs a new instance from a hash.
229 230 231 232 233 234 235 236 237 |
# File 'lib/vcr/structs.rb', line 229 def self.from_hash(hash) method = hash['method'] method &&= method.to_sym new method, hash['uri'], body_from(hash['body']), hash['headers'], :skip_port_stripping end |
Instance Method Details
#parsed_uri ⇒ #schema, ...
Parses the URI using the configured ‘uri_parser`.
242 243 244 |
# File 'lib/vcr/structs.rb', line 242 def parsed_uri VCR.configuration.uri_parser.parse(uri) end |
#to_hash ⇒ Hash
Builds a serializable hash from the request data.
216 217 218 219 220 221 222 223 |
# File 'lib/vcr/structs.rb', line 216 def to_hash { 'method' => method.to_s, 'uri' => uri, 'body' => serializable_body, 'headers' => headers }.tap { |h| OrderedHashSerializer.apply_to(h, members) } end |