spec/framework_spec/extensions/test-libs/webrick/httpstatus.rb in rhodes-3.2.0.beta.4 vs spec/framework_spec/extensions/test-libs/webrick/httpstatus.rb in rhodes-3.2.0.beta.5

- old
+ new

@@ -10,11 +10,22 @@ module WEBrick module HTTPStatus - class Status < StandardError; end + class Status < StandardError + def initialize(*args) + args[0] = AccessLog.escape(args[0]) unless args.empty? + super(*args) + end + class << self + attr_reader :code, :reason_phrase + end + def code() self::class::code end + def reason_phrase() self::class::reason_phrase end + alias to_i code + end class Info < Status; end class Success < Status; end class Redirect < Status; end class Error < Status; end class ClientError < Error; end @@ -65,329 +76,29 @@ 505 => 'HTTP Version Not Supported' } CodeToError = {} - class InternalServerError < ServerError - def code() 500 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end + StatusMessage.each{|code, message| + message.freeze + var_name = message.gsub(/[ \-]/,'_').upcase + err_name = message.gsub(/[ \-]/,'') - CodeToError[500] = const_get('InternalServerError') + case code + when 100...200; parent = Info + when 200...300; parent = Success + when 300...400; parent = Redirect + when 400...500; parent = ClientError + when 500...600; parent = ServerError + end - class PreconditionFailed < ClientError - def code() 412 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[412] = const_get('PreconditionFailed') - - class Unauthorized < ClientError - def code() 401 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[401] = const_get('Unauthorized') - - class Found < Redirect - def code() 302 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[302] = const_get('Found') - - class NonAuthoritativeInformation < Success - def code() 203 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[203] = const_get('NonAuthoritativeInformation') - - class ProxyAuthenticationRequired < ClientError - def code() 407 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[407] = const_get('ProxyAuthenticationRequired') - - class NotImplemented < ServerError - def code() 501 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[501] = const_get('NotImplemented') - - class RequestEntityTooLarge < ClientError - def code() 413 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[413] = const_get('RequestEntityTooLarge') - - class PaymentRequired < ClientError - def code() 402 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[402] = const_get('PaymentRequired') - - class SeeOther < Redirect - def code() 303 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[303] = const_get('SeeOther') - - class NoContent < Success - def code() 204 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[204] = const_get('NoContent') - - class RequestTimeout < ClientError - def code() 408 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[408] = const_get('RequestTimeout') - - class Continue < Info - def code() 100 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[100] = const_get('Continue') - - class BadGateway < ServerError - def code() 502 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[502] = const_get('BadGateway') - - class RequestURITooLarge < ClientError - def code() 414 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[414] = const_get('RequestURITooLarge') - - class Forbidden < ClientError - def code() 403 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[403] = const_get('Forbidden') - - class NotModified < Redirect - def code() 304 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[304] = const_get('NotModified') - - class ResetContent < Success - def code() 205 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[205] = const_get('ResetContent') - - class Conflict < ClientError - def code() 409 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[409] = const_get('Conflict') - - class OK < Success - def code() 200 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[200] = const_get('OK') - - class SwitchingProtocols < Info - def code() 101 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[101] = const_get('SwitchingProtocols') - - class ServiceUnavailable < ServerError - def code() 503 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[503] = const_get('ServiceUnavailable') - - class UnsupportedMediaType < ClientError - def code() 415 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[415] = const_get('UnsupportedMediaType') - - class NotFound < ClientError - def code() 404 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[404] = const_get('NotFound') - - class UseProxy < Redirect - def code() 305 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[305] = const_get('UseProxy') - - class PartialContent < Success - def code() 206 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[206] = const_get('PartialContent') - - class Gone < ClientError - def code() 410 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[410] = const_get('Gone') - - class MultipleChoices < Redirect - def code() 300 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[300] = const_get('MultipleChoices') - - class Created < Success - def code() 201 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[201] = const_get('Created') - - class GatewayTimeout < ServerError - def code() 504 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[504] = const_get('GatewayTimeout') - - class RequestRangeNotSatisfiable < ClientError - def code() 416 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[416] = const_get('RequestRangeNotSatisfiable') - - class MethodNotAllowed < ClientError - def code() 405 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[405] = const_get('MethodNotAllowed') - - class LengthRequired < ClientError - def code() 411 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[411] = const_get('LengthRequired') - - class BadRequest < ClientError - def code() 400 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[400] = const_get('BadRequest') - - class MovedPermanently < Redirect - def code() 301 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[301] = const_get('MovedPermanently') - - class Accepted < Success - def code() 202 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[202] = const_get('Accepted') - - class HTTPVersionNotSupported < ServerError - def code() 505 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[505] = const_get('HTTPVersionNotSupported') - - class ExpectationFailed < ClientError - def code() 417 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[417] = const_get('ExpectationFailed') - - class NotAcceptable < ClientError - def code() 406 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[406] = const_get('NotAcceptable') - - class TemporaryRedirect < Redirect - def code() 307 end - def reason_phrase() StatusMessage[code] end - alias to_i code - end - - CodeToError[307] = const_get('TemporaryRedirect') - + const_set("RC_#{var_name}", code) + err_class = Class.new(parent) + err_class.instance_variable_set(:@code, code) + err_class.instance_variable_set(:@reason_phrase, message) + const_set(err_name, err_class) + CodeToError[code] = err_class + } def reason_phrase(code) StatusMessage[code.to_i] end def info?(code)