Class: Soren::Request
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
: Soren::Types::Request::Body?.
-
#headers ⇒ Object
readonly
: Soren::Types::Request::Headers?.
-
#method ⇒ Object
readonly
: Soren::Types::Request::Method?.
-
#target ⇒ Object
readonly
: Soren::Types::Request::Target?.
Instance Method Summary collapse
-
#initialize(method:, target:, headers: {}, body: nil) ⇒ Request
constructor
: (method: untyped, target: untyped, ?headers: untyped, ?body: untyped) -> void.
-
#to_http(host:) ⇒ Object
: (host: String) -> String.
Constructor Details
#initialize(method:, target:, headers: {}, body: nil) ⇒ Request
: (method: untyped, target: untyped, ?headers: untyped, ?body: untyped) -> void
18 19 20 21 22 23 |
# File 'lib/soren/request.rb', line 18 def initialize(method:, target:, headers: {}, body: nil) @method = Soren::Types::Request::Method.new(method) #: Soren::Types::Request::Method @target = Soren::Types::Request::Target.new(target) #: Soren::Types::Request::Target @body = Soren::Types::Request::Body.new(body) #: Soren::Types::Request::Body @headers = Soren::Types::Request::Headers.new(headers, content_length: @body.to_http&.bytesize) #: Soren::Types::Request::Headers end |
Instance Attribute Details
#body ⇒ Object (readonly)
: Soren::Types::Request::Body?
15 16 17 |
# File 'lib/soren/request.rb', line 15 def body @body end |
#headers ⇒ Object (readonly)
: Soren::Types::Request::Headers?
14 15 16 |
# File 'lib/soren/request.rb', line 14 def headers @headers end |
#method ⇒ Object (readonly)
: Soren::Types::Request::Method?
12 13 14 |
# File 'lib/soren/request.rb', line 12 def method @method end |
#target ⇒ Object (readonly)
: Soren::Types::Request::Target?
13 14 15 |
# File 'lib/soren/request.rb', line 13 def target @target end |
Instance Method Details
#to_http(host:) ⇒ Object
: (host: String) -> String
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/soren/request.rb', line 26 def to_http(host:) request_line = "#{@method.to_http} #{@target.to_http} HTTP/1.1" header_lines = @headers.to_http(host: host) body_text = @body.to_http if body_text.nil? [request_line, *header_lines, '', ''].join("\r\n") else [request_line, *header_lines, '', body_text].join("\r\n") end end |