Class: Rbkb::Http::ResponseStatus
- Inherits:
-
Object
- Object
- 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.
378 379 380 381 |
# File 'lib/rbkb/http/headers.rb', line 378 def initialize(*args) _common_init(*args) @version ||= DEFAULT_HTTP_VERSION end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
398 399 400 |
# File 'lib/rbkb/http/headers.rb', line 398 def base @base end |
#code ⇒ Object
Returns the value of attribute code.
376 377 378 |
# File 'lib/rbkb/http/headers.rb', line 376 def code @code end |
#text ⇒ Object
Returns the value of attribute text.
376 377 378 |
# File 'lib/rbkb/http/headers.rb', line 376 def text @text end |
#version ⇒ Object
Returns the value of attribute version.
376 377 378 |
# File 'lib/rbkb/http/headers.rb', line 376 def version @version end |
Class Method Details
.parse(str) ⇒ Object
372 373 374 |
# File 'lib/rbkb/http/headers.rb', line 372 def self.parse(str) new().capture(str) end |
Instance Method Details
#capture(str) ⇒ Object
387 388 389 390 391 392 393 394 395 396 |
# File 'lib/rbkb/http/headers.rb', line 387 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
383 384 385 |
# File 'lib/rbkb/http/headers.rb', line 383 def to_raw [@version, @code, @text].join(" ") end |