Skip to content

Commit

Permalink
Added sumbol http status codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
NOX73 committed Dec 31, 2012
1 parent 60b4451 commit fd6995d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions celluloid-http.gemspec
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_runtime_dependency('rack')
gem.add_runtime_dependency('celluloid-io')
gem.add_runtime_dependency('http_parser.rb')

Expand Down
1 change: 1 addition & 0 deletions lib/celluloid-http.rb
Expand Up @@ -2,6 +2,7 @@
require "uri"
require "http_parser.rb"
require "celluloid/io"
require "rack"

module Celluloid
module Http
Expand Down
10 changes: 10 additions & 0 deletions lib/celluloid-http/response.rb
@@ -1,6 +1,8 @@
class Celluloid::Http::Response
extend Forwardable

STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES

def_delegators :parser, :<<

attr_writer :status
Expand Down Expand Up @@ -35,4 +37,12 @@ def parser
@parser ||= Http::Parser.new(self)
end

def reason
STATUS_CODES[status]
end

def sym_status
reason.downcase.gsub(/\s|-/, '_').to_sym
end

end
12 changes: 12 additions & 0 deletions test/unit/response_test.rb
Expand Up @@ -27,5 +27,17 @@ def test_parse_http_response
assert_equal "en", response.headers["Content-Language"]
end

def test_symbol_ok_http_status
response = Celluloid::Http::Response.new(200)

assert_equal :ok, response.sym_status
end

def test_symbol_not_found_http_status
response = Celluloid::Http::Response.new(404)

assert_equal :not_found, response.sym_status
end


end

0 comments on commit fd6995d

Please sign in to comment.