class VCR::Request
The request of an {HTTPInteraction}.
@attr [Symbol] method the HTTP method (i.e. :head, :options, :get, :post, :put, :patch or :delete) @attr [String] uri the request URI @attr [String, nil] body the request body @attr [Hash{String => Array<String>}] headers the request headers
Public Class Methods
from_hash(hash)
click to toggle source
Constructs a new instance from a hash.
@param [Hash] hash the hash to use to construct the instance. @return [Request] the request
# File lib/vcr/structs.rb, line 224 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
new(*args)
click to toggle source
Calls superclass method
VCR::Normalizers::Body.new
# File lib/vcr/structs.rb, line 194 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
Public Instance Methods
method(*args)
click to toggle source
Calls superclass method
# File lib/vcr/structs.rb, line 242 def method(*args) return super if args.empty? @@object_method.bind(self).call(*args) end
parsed_uri()
click to toggle source
Parses the URI using the configured `uri_parser`.
@return [#schema, host, port, path, query] A parsed URI object.
# File lib/vcr/structs.rb, line 237 def parsed_uri VCR.configuration.uri_parser.parse(uri) end
to_hash()
click to toggle source
Builds a serializable hash from the request data.
@return [Hash] hash that represents this request and can be easily
serialized.
@see ::from_hash
# File lib/vcr/structs.rb, line 211 def to_hash { 'method' => method.to_s, 'uri' => uri, 'body' => serializable_body, 'headers' => headers }.tap { |h| OrderedHashSerializer.apply_to(h, members) } end
Private Instance Methods
without_standard_port(uri)
click to toggle source
# File lib/vcr/structs.rb, line 329 def without_standard_port(uri) return uri if uri.nil? u = parsed_uri return uri unless [['http', 80], ['https', 443]].include?([u.scheme, u.port]) u.port = nil u.to_s end