Class: HttpParser::Instance
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- HttpParser::Instance
- Defined in:
- lib/http-parser/types.rb
Overview
Effectively this represents a request instance
Instance Method Summary collapse
-
#data ⇒ FFI::Pointer
Additional data attached to the parser.
-
#error ⇒ StandarError
Returns the error that occurred during processing.
-
#error! ⇒ Object
Indicates an error has occurred when called in a callback.
-
#error? ⇒ Boolean
Determines whether an error occurred during processing.
-
#flags ⇒ Integer
Flags for the parser.
-
#http_major ⇒ Integer
The parsed HTTP major version number.
-
#http_method ⇒ Symbol
The parsed HTTP Method.
-
#http_minor ⇒ Integer
The parsed HTTP minor version number.
-
#http_status ⇒ Integer
The parsed HTTP response Status Code.
-
#http_version ⇒ String
The parsed HTTP version.
-
#initialize(ptr = nil) {|_self| ... } ⇒ Instance
constructor
A new instance of Instance.
-
#keep_alive? ⇒ Boolean
Determines whether the ‘Connection: keep-alive` header has been parsed.
-
#reset!(new_type = type) ⇒ Object
Resets the parser.
-
#stop! ⇒ Object
Halts the parser if called in a callback.
-
#type ⇒ :request, ...
The type of the parser.
-
#type=(new_type) ⇒ Object
Sets the type of the parser.
-
#upgrade? ⇒ Boolean
Determines whether the ‘Upgrade` header has been parsed.
Constructor Details
#initialize(ptr = nil) {|_self| ... } ⇒ Instance
Returns a new instance of Instance.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/http-parser/types.rb', line 95 def initialize(ptr = nil) if ptr then super(ptr) else super() self.type = :both end yield self if block_given? ::HttpParser.http_parser_init(self, self.type) unless ptr end |
Instance Method Details
#data ⇒ FFI::Pointer
Additional data attached to the parser.
246 247 248 |
# File 'lib/http-parser/types.rb', line 246 def data self[:data] end |
#error ⇒ StandarError
Returns the error that occurred during processing.
230 231 232 233 234 235 236 237 238 |
# File 'lib/http-parser/types.rb', line 230 def error error = (self[:error_upgrade] & 0b1111111) return nil if error == 0 err = ::HttpParser.err_name(error)[4..-1] # HPE_ is at the start of all these errors klass = ERRORS[err.to_sym] err = "#{::HttpParser.err_desc(error)} (#{err})" return klass.nil? ? Error::UNKNOWN.new(err) : klass.new(err) end |
#error! ⇒ Object
Indicates an error has occurred when called in a callback
273 274 275 |
# File 'lib/http-parser/types.rb', line 273 def error! throw :return, -1 end |
#error? ⇒ Boolean
Determines whether an error occurred during processing.
219 220 221 222 |
# File 'lib/http-parser/types.rb', line 219 def error? error = (self[:error_upgrade] & 0b1111111) return error != 0 end |
#flags ⇒ Integer
Flags for the parser.
143 144 145 |
# File 'lib/http-parser/types.rb', line 143 def flags (self[:type_flags] & 0xfc) end |
#http_major ⇒ Integer
The parsed HTTP major version number.
153 154 155 |
# File 'lib/http-parser/types.rb', line 153 def http_major self[:http_major] end |
#http_method ⇒ Symbol
The parsed HTTP Method.
197 198 199 |
# File 'lib/http-parser/types.rb', line 197 def http_method METHODS[self[:method]] end |
#http_minor ⇒ Integer
The parsed HTTP minor version number.
163 164 165 |
# File 'lib/http-parser/types.rb', line 163 def http_minor self[:http_minor] end |
#http_status ⇒ Integer
The parsed HTTP response Status Code.
185 186 187 |
# File 'lib/http-parser/types.rb', line 185 def http_status self[:status_code] end |
#http_version ⇒ String
The parsed HTTP version.
173 174 175 |
# File 'lib/http-parser/types.rb', line 173 def http_version "%d.%d" % [self[:http_major], self[:http_minor]] end |
#keep_alive? ⇒ Boolean
Determines whether the ‘Connection: keep-alive` header has been parsed.
259 260 261 |
# File 'lib/http-parser/types.rb', line 259 def keep_alive? ::HttpParser.http_should_keep_alive(self) > 0 end |
#reset!(new_type = type) ⇒ Object
Resets the parser.
113 114 115 |
# File 'lib/http-parser/types.rb', line 113 def reset!(new_type = type) ::HttpParser.http_parser_init(self, new_type) end |
#stop! ⇒ Object
Halts the parser if called in a callback
266 267 268 |
# File 'lib/http-parser/types.rb', line 266 def stop! throw :return, 1 end |
#type ⇒ :request, ...
The type of the parser.
123 124 125 |
# File 'lib/http-parser/types.rb', line 123 def type TYPES[self[:type_flags] & 0x3] end |
#type=(new_type) ⇒ Object
Sets the type of the parser.
133 134 135 |
# File 'lib/http-parser/types.rb', line 133 def type=(new_type) self[:type_flags] = (flags | TYPES[new_type]) end |
#upgrade? ⇒ Boolean
Determines whether the ‘Upgrade` header has been parsed.
209 210 211 |
# File 'lib/http-parser/types.rb', line 209 def upgrade? (self[:error_upgrade] & 0b10000000) > 0 end |