Class: Cybertrain::Test::ReceivedRequest

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/test/http_receiver.rb

Overview

One request as the receiver read it. Method names carry an http_ prefix: a framework class that defines body or headers next to another one returning a different type confuses Spinel’s inference (spikes/NOTES.md rules 10, 34).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#http_body ⇒ String (readonly)

Returns the body (a chunked body decoded), “” for none.

Returns:

  • (String) —

    the body (a chunked body decoded), “” for none



30
31
32
# File 'cybertrain/test/http_receiver.rb', line 30

def http_body
  @http_body
end

#http_headers ⇒ Hash{String => String} (readonly)

Returns lowercased names; repeated headers joined with “, “.

Returns:

  • (Hash{String => String}) —

    lowercased names; repeated headers joined with “, “



26
27
28
# File 'cybertrain/test/http_receiver.rb', line 26

def http_headers
  @http_headers
end

#http_method ⇒ String (readonly)

Returns “GET”, “POST”, …

Returns:

  • (String) —

    “GET”, “POST”, …



17
18
19
# File 'cybertrain/test/http_receiver.rb', line 17

def http_method
  @http_method
end

#http_target ⇒ String (readonly)

Returns the request target as sent: path and query.

Returns:

  • (String) —

    the request target as sent: path and query



21
22
23
# File 'cybertrain/test/http_receiver.rb', line 21

def http_target
  @http_target
end

Instance Method Details

#http_header(name) ⇒ String

A header’s value by name (any case), “” when it was not sent.

Parameters:

  • name (String)

Returns:

  • (String)


43
44
45
46
# File 'cybertrain/test/http_receiver.rb', line 43

def http_header(name)
  value = @http_headers[name.to_s.downcase]
  value.nil? ? "" : value.to_s
end

#http_path ⇒ String

The target without its query string.

Returns:

  • (String)


51
52
53
54
# File 'cybertrain/test/http_receiver.rb', line 51

def http_path
  at = @http_target.byteindex("?")
  at.nil? ? @http_target : @http_target.byteslice(0, at)
end