Class: Rbkb::Http::ResponseStatus
- Includes:
- CommonInterface
- Defined in:
- lib/rbkb/http/headers.rb
Overview
A class for HTTP response status messages, i.e. the first header returned by a server, as in “HTTP/1.0 200 OK”
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#code ⇒ Object
Returns the value of attribute code.
-
#text ⇒ Object
Returns the value of attribute text.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #capture(str) ⇒ Object
-
#initialize(*args) ⇒ ResponseStatus
constructor
A new instance of ResponseStatus.
- #to_raw ⇒ Object
Methods included from CommonInterface
Constructor Details
#initialize(*args) ⇒ ResponseStatus
Returns a new instance of ResponseStatus.
342 343 344 345 |
# File 'lib/rbkb/http/headers.rb', line 342 def initialize(*args) _common_init(*args) @version ||= DEFAULT_HTTP_VERSION end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
362 363 364 |
# File 'lib/rbkb/http/headers.rb', line 362 def base @base end |
#code ⇒ Object
Returns the value of attribute code.
340 341 342 |
# File 'lib/rbkb/http/headers.rb', line 340 def code @code end |
#text ⇒ Object
Returns the value of attribute text.
340 341 342 |
# File 'lib/rbkb/http/headers.rb', line 340 def text @text end |
#version ⇒ Object
Returns the value of attribute version.
340 341 342 |
# File 'lib/rbkb/http/headers.rb', line 340 def version @version end |
Class Method Details
.parse(str) ⇒ Object
336 337 338 |
# File 'lib/rbkb/http/headers.rb', line 336 def self.parse(str) new().capture(str) end |
Instance Method Details
#capture(str) ⇒ Object
351 352 353 354 355 356 357 358 359 360 |
# File 'lib/rbkb/http/headers.rb', line 351 def capture(str) raise "arg 0 must be a string" unless str.is_a?(String) unless m=/^([^\s]+)\s+(\d+)(?:\s+(.*))?$/.match(str) raise "invalid status #{str.inspect}" end @version = m[1] @code = m[2] =~ /^\d+$/ ? m[2].to_i : m[2] @text = m[3] return self end |
#to_raw ⇒ Object
347 348 349 |
# File 'lib/rbkb/http/headers.rb', line 347 def to_raw [@version, @code, @text].join(" ") end |