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.
-
#final_chunk? ⇒ Boolean
Determines if a chunked response has completed.
-
#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.
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/http-parser/types.rb', line 106 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.
257 258 259 |
# File 'lib/http-parser/types.rb', line 257 def data self[:data] end |
#error ⇒ StandarError
Returns the error that occurred during processing.
241 242 243 244 245 246 247 248 249 |
# File 'lib/http-parser/types.rb', line 241 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
294 295 296 |
# File 'lib/http-parser/types.rb', line 294 def error! throw :return, -1 end |
#error? ⇒ Boolean
Determines whether an error occurred during processing.
230 231 232 233 |
# File 'lib/http-parser/types.rb', line 230 def error? error = (self[:error_upgrade] & 0b1111111) return error != 0 end |
#final_chunk? ⇒ Boolean
Determines if a chunked response has completed
280 281 282 |
# File 'lib/http-parser/types.rb', line 280 def final_chunk? ::HttpParser.http_body_is_final(self) > 0 end |
#flags ⇒ Integer
Flags for the parser.
154 155 156 |
# File 'lib/http-parser/types.rb', line 154 def flags (self[:type_flags] & 0xfc) end |
#http_major ⇒ Integer
The parsed HTTP major version number.
164 165 166 |
# File 'lib/http-parser/types.rb', line 164 def http_major self[:http_major] end |
#http_method ⇒ Symbol
The parsed HTTP Method.
208 209 210 |
# File 'lib/http-parser/types.rb', line 208 def http_method METHODS[self[:method]] end |
#http_minor ⇒ Integer
The parsed HTTP minor version number.
174 175 176 |
# File 'lib/http-parser/types.rb', line 174 def http_minor self[:http_minor] end |
#http_status ⇒ Integer
The parsed HTTP response Status Code.
196 197 198 |
# File 'lib/http-parser/types.rb', line 196 def http_status self[:status_code] end |
#http_version ⇒ String
The parsed HTTP version.
184 185 186 |
# File 'lib/http-parser/types.rb', line 184 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.
270 271 272 |
# File 'lib/http-parser/types.rb', line 270 def keep_alive? ::HttpParser.http_should_keep_alive(self) > 0 end |
#reset!(new_type = type) ⇒ Object
Resets the parser.
124 125 126 |
# File 'lib/http-parser/types.rb', line 124 def reset!(new_type = type) ::HttpParser.http_parser_init(self, new_type) end |
#stop! ⇒ Object
Halts the parser if called in a callback
287 288 289 |
# File 'lib/http-parser/types.rb', line 287 def stop! throw :return, 1 end |
#type ⇒ :request, ...
The type of the parser.
134 135 136 |
# File 'lib/http-parser/types.rb', line 134 def type TYPES[self[:type_flags] & 0x3] end |
#type=(new_type) ⇒ Object
Sets the type of the parser.
144 145 146 |
# File 'lib/http-parser/types.rb', line 144 def type=(new_type) self[:type_flags] = (flags | TYPES[new_type]) end |
#upgrade? ⇒ Boolean
Determines whether the ‘Upgrade` header has been parsed.
220 221 222 |
# File 'lib/http-parser/types.rb', line 220 def upgrade? (self[:error_upgrade] & 0b10000000) > 0 end |