diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-16 21:12:00 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-16 21:12:00 +0000 |
commit | be3911733043df19c9f57609a055f1a826d496f0 (patch) | |
tree | 1cce5f9ee739c5292dee2f1d200865f44946b32f /lib/webrick/httpstatus.rb | |
parent | 772a2811923e1634ff7c157abdc9b41740659af6 (diff) | |
download | ruby-be3911733043df19c9f57609a055f1a826d496f0.tar.gz |
* lib/webrick/log.rb: Improve documentation of BasicLog and Log.
Patch by Olivier Brisse. [Ruby 1.9 - Bug #4833]
* lib/webrick/httpstatus.rb: Improve documentation of
WEBrick::HTTPStatus. Patch by Olivier Brisse.
[Ruby 1.9 - Bug #4833]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/httpstatus.rb')
-rw-r--r-- | lib/webrick/httpstatus.rb | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/lib/webrick/httpstatus.rb b/lib/webrick/httpstatus.rb index ecf0201a28..9eee38a40f 100644 --- a/lib/webrick/httpstatus.rb +++ b/lib/webrick/httpstatus.rb @@ -10,30 +10,50 @@ module WEBrick + ## + # This module is used to manager HTTP status codes. + # + # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more + # information. module HTTPStatus + ## + # Root of the HTTP status class hierarchy class Status < StandardError - def initialize(*args) + def initialize(*args) # :nodoc: args[0] = AccessLog.escape(args[0]) unless args.empty? super(*args) end class << self - attr_reader :code, :reason_phrase + attr_reader :code, :reason_phrase # :nodoc: end + + # Returns the HTTP status code def code() self::class::code end + + # Returns the HTTP status description def reason_phrase() self::class::reason_phrase end - alias to_i code + + alias to_i code # :nodoc: end + + # Root of the HTTP info statuses class Info < Status; end + # Root of the HTTP sucess statuses class Success < Status; end + # Root of the HTTP redirect statuses class Redirect < Status; end + # Root of the HTTP error statuses class Error < Status; end + # Root of the HTTP client error statuses class ClientError < Error; end + # Root of the HTTP server error statuses class ServerError < Error; end class EOFError < StandardError; end - StatusMessage = { + # HTTP status codes and descriptions + StatusMessage = { # :nodoc: 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', @@ -76,8 +96,11 @@ module WEBrick 505 => 'HTTP Version Not Supported' } - CodeToError = {} + # Maps a status code to the corresponding Status class + CodeToError = {} # :nodoc: + # Creates a status or error class for each status code and + # populates the CodeToError map. StatusMessage.each{|code, message| message.freeze var_name = message.gsub(/[ \-]/,'_').upcase @@ -99,28 +122,57 @@ module WEBrick CodeToError[code] = err_class } + ## + # Returns the description corresponding to the HTTP status +code+ + # + # WEBrick::HTTPStatus.reason_phrase 404 + # => "Not Found" def reason_phrase(code) StatusMessage[code.to_i] end + + ## + # Is +code+ an informational status? def info?(code) code.to_i >= 100 and code.to_i < 200 end + + ## + # Is +code+ a successful status? def success?(code) code.to_i >= 200 and code.to_i < 300 end + + ## + # Is +code+ a redirection status? def redirect?(code) code.to_i >= 300 and code.to_i < 400 end + + ## + # Is +code+ an error status? def error?(code) code.to_i >= 400 and code.to_i < 600 end + + ## + # Is +code+ a client error status? def client_error?(code) code.to_i >= 400 and code.to_i < 500 end + + ## + # Is +code+ a server error status? def server_error?(code) code.to_i >= 500 and code.to_i < 600 end + ## + # Returns the status class corresponding to +code+ + # + # WEBrick::HTTPStatus[302] + # => WEBrick::HTTPStatus::NotFound + # def self.[](code) CodeToError[code] end |