Class: VCR::Request

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Normalizers::Body

included

Constructor Details

#initialize(*args) ⇒ Request

Returns a new instance of Request.



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/vcr/structs.rb', line 180

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

#bodyString?

the request body

Returns:

  • (String, nil)

    the current value of body



176
177
178
# File 'lib/vcr/structs.rb', line 176

def body
  @body
end

#headersHash{String => Array<String>}

the request headers

Returns:

  • (Hash{String => Array<String>})

    the current value of headers



176
177
178
# File 'lib/vcr/structs.rb', line 176

def headers
  @headers
end

#method(*args) ⇒ Symbol

the HTTP method (i.e. :head, :options, :get, :post, :put, :patch or :delete)

Returns:

  • (Symbol)

    the current value of method



176
177
178
# File 'lib/vcr/structs.rb', line 176

def method
  @method
end

#uriString

the request URI

Returns:

  • (String)

    the current value of uri



176
177
178
# File 'lib/vcr/structs.rb', line 176

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Request

Constructs a new instance from a hash.

Parameters:

  • hash (Hash)

    the hash to use to construct the instance.

Returns:



210
211
212
213
214
215
216
217
218
# File 'lib/vcr/structs.rb', line 210

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`.

Returns:

  • (#schema, #host, #port, #path, #query)

    A parsed URI object.



223
224
225
# File 'lib/vcr/structs.rb', line 223

def parsed_uri
  VCR.configuration.uri_parser.parse(uri)
end

#to_hashHash

Builds a serializable hash from the request data.

Returns:

  • (Hash)

    hash that represents this request and can be easily serialized.

See Also:



197
198
199
200
201
202
203
204
# File 'lib/vcr/structs.rb', line 197

def to_hash
  {
    'method'  => method.to_s,
    'uri'     => uri,
    'body'    => serializable_body,
    'headers' => headers
  }
end