Class: Rbkb::Http::ResponseStatus

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonInterface

#_common_init, #opts, #opts=

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

#baseObject

Returns the value of attribute base.



398
399
400
# File 'lib/rbkb/http/headers.rb', line 398

def base
  @base
end

#codeObject

Returns the value of attribute code.



376
377
378
# File 'lib/rbkb/http/headers.rb', line 376

def code
  @code
end

#textObject

Returns the value of attribute text.



376
377
378
# File 'lib/rbkb/http/headers.rb', line 376

def text
  @text
end

#versionObject

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_rawObject



383
384
385
# File 'lib/rbkb/http/headers.rb', line 383

def to_raw
  [@version, @code, @text].join(" ")
end