Class: RaptorIO::Protocol::HTTP::Message
- Inherits:
-
Object
- Object
- RaptorIO::Protocol::HTTP::Message
- Defined in:
- lib/raptor-io/protocol/http/message.rb
Overview
Instance Attribute Summary collapse
- #body ⇒ String
-
#headers ⇒ Headers<String, String>
readonly
HTTP headers as a Hash-like object.
-
#version ⇒ String
readonly
HTTP version.
Instance Method Summary collapse
-
#http_1_0? ⇒ Boolean
‘true` when #version is `1.0`, `false` otherwise.
-
#http_1_1? ⇒ Boolean
‘true` when #version is `1.1`, `false` otherwise.
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
-
#keep_alive? ⇒ Bool
‘true` if the connections should be reused, `false` otherwise.
Constructor Details
#initialize(options = {}) ⇒ Message
Note:
All options will be sent through the class setters whenever possible to allow for normalization.
Returns a new instance of Message.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/raptor-io/protocol/http/message.rb', line 30 def initialize( = {} ) .each do |k, v| begin send( "#{k}=", v ) rescue NoMethodError instance_variable_set( "@#{k}".to_sym, v ) end end @headers = Headers.new( @headers ) @version ||= '1.1' end |
Instance Attribute Details
#body ⇒ String
18 19 20 |
# File 'lib/raptor-io/protocol/http/message.rb', line 18 def body @body end |
#headers ⇒ Headers<String, String> (readonly)
Returns HTTP headers as a Hash-like object.
15 16 17 |
# File 'lib/raptor-io/protocol/http/message.rb', line 15 def headers @headers end |
#version ⇒ String (readonly)
Returns HTTP version.
12 13 14 |
# File 'lib/raptor-io/protocol/http/message.rb', line 12 def version @version end |
Instance Method Details
#http_1_0? ⇒ Boolean
Returns ‘true` when #version is `1.0`, `false` otherwise.
60 61 62 |
# File 'lib/raptor-io/protocol/http/message.rb', line 60 def http_1_0? version == '1.0' end |
#http_1_1? ⇒ Boolean
Returns ‘true` when #version is `1.1`, `false` otherwise.
54 55 56 |
# File 'lib/raptor-io/protocol/http/message.rb', line 54 def http_1_1? version == '1.1' end |
#keep_alive? ⇒ Bool
Returns ‘true` if the connections should be reused, `false` otherwise.
45 46 47 48 49 50 |
# File 'lib/raptor-io/protocol/http/message.rb', line 45 def keep_alive? connection = headers['Connection'].to_s.downcase return connection == 'keep-alive' if version.to_f < 1.1 connection != 'close' end |