Class: SHL::Request
- Inherits:
-
Object
- Object
- SHL::Request
- Includes:
- AttributeInitializer
- Defined in:
- lib/shl/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#url ⇒ Object
Returns the value of attribute url.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
- #connection ⇒ Object
- #path ⇒ Object
- #request_line ⇒ Object
- #run ⇒ Object
- #serialized_body ⇒ Object
- #serialized_headers ⇒ Object
Methods included from AttributeInitializer
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/shl/request.rb', line 3 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/shl/request.rb', line 3 def headers @headers end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/shl/request.rb', line 3 def url @url end |
#verb ⇒ Object
Returns the value of attribute verb.
3 4 5 |
# File 'lib/shl/request.rb', line 3 def verb @verb end |
Instance Method Details
#connection ⇒ Object
15 16 17 |
# File 'lib/shl/request.rb', line 15 def connection @connection ||= TCPSocket.new(@url.host, @url.port) end |
#path ⇒ Object
11 12 13 |
# File 'lib/shl/request.rb', line 11 def path @url.path == '' ? '/' : @url.path end |
#request_line ⇒ Object
19 20 21 |
# File 'lib/shl/request.rb', line 19 def request_line "#{verb.to_s.upcase} #{path} #{HTTP_VERSION}" end |
#run ⇒ Object
40 41 42 43 44 |
# File 'lib/shl/request.rb', line 40 def run connection.write([request_line,serialized_headers,serialized_body].join(NEWLINE)) connection.flush Response.new(:io=>connection) end |
#serialized_body ⇒ Object
36 37 38 |
# File 'lib/shl/request.rb', line 36 def serialized_body @body.to_s + NEWLINE end |
#serialized_headers ⇒ Object
30 31 32 33 34 |
# File 'lib/shl/request.rb', line 30 def serialized_headers headers.map do |key, value| "#{key}: #{value}" end.join(NEWLINE) end |