Permalink
Browse files

Revert "Add common HTTP strings to Rack::Const"

This reverts commit 6ae0a10.
  • Loading branch information...
1 parent 0acfeae commit 71030b9dbea07d4e573803805ff430d52a542607 @josh josh committed Aug 5, 2009
View
@@ -32,7 +32,6 @@ def self.release
autoload :Chunked, "rack/chunked"
autoload :CommonLogger, "rack/commonlogger"
autoload :ConditionalGet, "rack/conditionalget"
- autoload :Const, "rack/constants"
autoload :ContentLength, "rack/content_length"
autoload :ContentType, "rack/content_type"
autoload :File, "rack/file"
@@ -6,9 +6,9 @@ def initialize(app)
end
def call(env)
- env[Const::ENV_PATH_INFO] ||= ""
- env[Const::ENV_SCRIPT_NAME] ||= ""
- controller = @app.run(env[Const::RACK_INPUT], env)
+ env["PATH_INFO"] ||= ""
+ env["SCRIPT_NAME"] ||= ""
+ controller = @app.run(env['rack.input'], env)
h = controller.headers
h.each_pair do |k,v|
if v.kind_of? URI
@@ -17,17 +17,17 @@ def initialize(app, realm=nil, &authenticator)
def unauthorized(www_authenticate = challenge)
return [ 401,
- { Const::CONTENT_TYPE => 'text/plain',
- Const::CONTENT_LENGTH => '0',
+ { 'Content-Type' => 'text/plain',
+ 'Content-Length' => '0',
'WWW-Authenticate' => www_authenticate.to_s },
[]
]
end
def bad_request
return [ 400,
- { Const::CONTENT_TYPE => 'text/plain',
- Const::CONTENT_LENGTH => '0' },
+ { 'Content-Type' => 'text/plain',
+ 'Content-Length' => '0' },
[]
]
end
View
@@ -20,7 +20,7 @@ def call(env)
return bad_request unless auth.basic?
if valid?(auth)
- env[Const::ENV_REMOTE_USER] = auth.username
+ env['REMOTE_USER'] = auth.username
return @app.call(env)
end
@@ -45,7 +45,7 @@ def call(env)
if auth.nonce.stale?
return unauthorized(challenge(:stale => true))
else
- env[Const::ENV_REMOTE_USER] = auth.username
+ env['REMOTE_USER'] = auth.username
return @app.call(env)
end
@@ -8,15 +8,15 @@ module Digest
class Request < Auth::AbstractRequest
def method
- @env['rack.methodoverride.original_method'] || @env[Const::ENV_REQUEST_METHOD]
+ @env['rack.methodoverride.original_method'] || @env['REQUEST_METHOD']
end
def digest?
:digest == scheme
end
def correct_uri?
- (@env[Const::ENV_SCRIPT_NAME].to_s + @env[Const::ENV_PATH_INFO].to_s) == uri
+ (@env['SCRIPT_NAME'].to_s + @env['PATH_INFO'].to_s) == uri
end
def nonce
View
@@ -89,7 +89,7 @@ module Auth
# The first argument is an OpenID::Response, the second is a
# Rack::Request of the current request, the last is the hash used in
# ruby-openid handling, which can be found manually at
- # env[Const::RACK_SESSION][:openid].
+ # env['rack.session'][:openid].
#
# This is useful if you wanted to expand the processing done, such as
# setting up user accounts.
@@ -98,7 +98,7 @@ module Auth
# def oid_app.success oid, request, session
# user = Models::User[oid.identity_url]
# user ||= Models::User.create_from_openid oid
- # request[Const::RACK_SESSION][:user] = user.id
+ # request['rack.session'][:user] = user.id
# redirect MyApp.site_home
# end
#
@@ -133,7 +133,7 @@ class BadExtension < RuntimeError; end
# the current request is used.
#
# <tt>:session_key</tt> defines the key to the session hash in the env.
- # The default is Const::RACK_SESSION.
+ # The default is 'rack.session'.
#
# <tt>:openid_param</tt> defines at what key in the request parameters to
# find the identifier to resolve. As per the 2.0 spec, the default is
@@ -159,7 +159,7 @@ def initialize(realm, options={})
and realm.fragment.nil? \
and realm.scheme =~ /^https?$/ \
and realm.host =~ /^(\*\.)?#{URI::REGEXP::PATTERN::URIC_NO_SLASH}+/
- realm.path = Const::SLASH if realm.path.empty?
+ realm.path = '/' if realm.path.empty?
@realm = realm.to_s
if ruri = options[:return_to]
@@ -173,7 +173,7 @@ def initialize(realm, options={})
@return_to = ruri.to_s
end
- @session_key = options[:session_key] || Const::RACK_SESSION
+ @session_key = options[:session_key] || 'rack.session'
@openid_param = options[:openid_param] || 'openid_identifier'
@store = options[:store] || ::OpenID::Store::Memory.new
@immediate = !!options[:immediate]
@@ -235,7 +235,7 @@ def call(env)
# If all parameters fit within the max length of a URI, a 303 redirect
# will be returned. Otherwise #confirm_post_params will be called.
#
- # Any messages from OpenID's request are logged to env[Const::RACK_ERRORS]
+ # Any messages from OpenID's request are logged to env['rack.errors']
#
# <tt>env['rack.auth.openid.request']</tt> is the openid checkid request
# instance.
@@ -249,7 +249,7 @@ def call(env)
def check(consumer, session, req)
oid = consumer.begin(req.GET[@openid_param], @anonymous)
req.env['rack.auth.openid.request'] = oid
- req.env[Const::RACK_ERRORS].puts(oid.message)
+ req.env['rack.errors'].puts(oid.message)
p oid if $DEBUG
## Extension support
@@ -269,7 +269,7 @@ def check(consumer, session, req)
end
rescue ::OpenID::DiscoveryFailure => e
# thrown from inside OpenID::Consumer#begin by yadis stuff
- req.env[Const::RACK_ERRORS].puts( [e.message, *e.backtrace]*"\n" )
+ req.env['rack.errors'].puts( [e.message, *e.backtrace]*"\n" )
return foreign_server_failure
end
@@ -278,15 +278,15 @@ def check(consumer, session, req)
# Data gathered from extensions are stored in session[:openid] with the
# extension's namespace uri as the key.
#
- # Any messages from OpenID's response are logged to env[Const::RACK_ERRORS]
+ # Any messages from OpenID's response are logged to env['rack.errors']
#
# <tt>env['rack.auth.openid.response']</tt> will contain the openid
# response.
def finish(consumer, session, req)
oid = consumer.complete(req.GET, req.url)
req.env['rack.auth.openid.response'] = oid
- req.env[Const::RACK_ERRORS].puts(oid.message)
+ req.env['rack.errors'].puts(oid.message)
p oid if $DEBUG
if ValidStatus.include?(oid.status)
@@ -366,37 +366,37 @@ def confirm_post_params(oid, realm, return_to, immediate)
# argument.
def redirect(uri)
- [ 303, {Const::CONTENT_TYPE=>'text/plain', Const::CONTENT_LENGTH=>'0',
+ [ 303, {'Content-Type'=>'text/plain', 'Content-Length'=>'0',
'Location' => uri},
[] ]
end
# Returns an empty 400 response.
def bad_request
- [ 400, {Const::CONTENT_TYPE=>'text/plain', Const::CONTENT_LENGTH=>'0'},
+ [ 400, {'Content-Type'=>'text/plain', 'Content-Length'=>'0'},
[''] ]
end
# Returns a basic unauthorized 401 response.
def unauthorized
- [ 401, {Const::CONTENT_TYPE => 'text/plain', Const::CONTENT_LENGTH => '13'},
+ [ 401, {'Content-Type' => 'text/plain', 'Content-Length' => '13'},
['Unauthorized.'] ]
end
# Returns a basic access denied 403 response.
def access_denied
- [ 403, {Const::CONTENT_TYPE => 'text/plain', Const::CONTENT_LENGTH => '14'},
+ [ 403, {'Content-Type' => 'text/plain', 'Content-Length' => '14'},
['Access denied.'] ]
end
# Returns a 503 response to be used if communication with the remote
# OpenID server fails.
def foreign_server_failure
- [ 503, {Const::CONTENT_TYPE=>'text/plain', Const::CONTENT_LENGTH => '23'},
+ [ 503, {'Content-Type'=>'text/plain', 'Content-Length' => '23'},
['Foreign server failure.'] ]
end
@@ -452,7 +452,7 @@ def failure(oid, request, session)
def invalid_status(oid, request, session)
msg = 'Invalid status returned by the OpenID authorization reponse.'
[ 500,
- {Const::CONTENT_TYPE=>'text/plain',Const::CONTENT_LENGTH=>msg.length.to_s},
+ {'Content-Type'=>'text/plain','Content-Length'=>msg.length.to_s},
[msg] ]
end
end
@@ -463,7 +463,7 @@ def invalid_status(oid, request, session)
#
# use Rack::Session::Pool
# use Rack::Auth::OpenIDAuth, realm, openid_options do |env|
- # env[Const::RACK_SESSION][:authkey] == a_string
+ # env['rack.session'][:authkey] == a_string
# end
# run RackApp
#
View
@@ -17,7 +17,7 @@ module Rack
#
# app = Rack::Builder.app do
# use Rack::CommonLogger
- # lambda { |env| [200, {Const::CONTENT_TYPE => 'text/plain'}, 'OK'] }
+ # lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] }
# end
#
# +use+ adds a middleware to the stack, +run+ dispatches to an application.
View
@@ -15,10 +15,10 @@ def call(env)
status, headers, body = @app.call(env)
headers = HeaderHash.new(headers)
- if env[Const::ENV_HTTP_VERSION] == 'HTTP/1.0' ||
+ if env['HTTP_VERSION'] == 'HTTP/1.0' ||
STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
- headers[Const::CONTENT_LENGTH] ||
- headers[Const::TRANSFER_ENCODING]
+ headers['Content-Length'] ||
+ headers['Transfer-Encoding']
[status, headers.to_hash, body]
else
dup.chunk(status, headers, body)
@@ -27,8 +27,8 @@ def call(env)
def chunk(status, headers, body)
@body = body
- headers.delete(Const::CONTENT_LENGTH)
- headers[Const::TRANSFER_ENCODING] = 'chunked'
+ headers.delete('Content-Length')
+ headers['Transfer-Encoding'] = 'chunked'
[status, headers.to_hash, self]
end
View
@@ -26,15 +26,15 @@ def log(env, status, header, began_at)
now = Time.now
length = extract_content_length(header)
- logger = @logger || env[Const::RACK_ERRORS]
+ logger = @logger || env['rack.errors']
logger.write FORMAT % [
- env[Const::ENV_HTTP_X_FORWARDED_FOR] || env[Const::ENV_REMOTE_ADDR] || "-",
- env[Const::ENV_REMOTE_USER] || "-",
+ env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
+ env["REMOTE_USER"] || "-",
now.strftime("%d/%b/%Y %H:%M:%S"),
- env[Const::ENV_REQUEST_METHOD],
- env[Const::ENV_PATH_INFO],
- env[Const::ENV_QUERY_STRING].empty? ? Const::EMPTY_STRING : "?"+env[Const::ENV_QUERY_STRING],
- env[Const::ENV_HTTP_VERSION],
+ env["REQUEST_METHOD"],
+ env["PATH_INFO"],
+ env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
+ env["HTTP_VERSION"],
status.to_s[0..3],
length,
now - began_at ]
View
@@ -20,27 +20,27 @@ def initialize(app)
end
def call(env)
- return @app.call(env) unless %w[GET HEAD].include?(env[Const::ENV_REQUEST_METHOD])
+ return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD'])
status, headers, body = @app.call(env)
headers = Utils::HeaderHash.new(headers)
if etag_matches?(env, headers) || modified_since?(env, headers)
status = 304
- headers.delete(Const::CONTENT_TYPE)
- headers.delete(Const::CONTENT_LENGTH)
+ headers.delete('Content-Type')
+ headers.delete('Content-Length')
body = []
end
[status, headers, body]
end
private
def etag_matches?(env, headers)
- etag = headers[Const::ETAG] and etag == env[Const::ENV_HTTP_IF_NONE_MATCH]
+ etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH']
end
def modified_since?(env, headers)
- last_modified = headers[Const::LAST_MODIFIED] and
- last_modified == env[Const::ENV_HTTP_IF_MODIFIED_SINCE]
+ last_modified = headers['Last-Modified'] and
+ last_modified == env['HTTP_IF_MODIFIED_SINCE']
end
end
View
@@ -1,55 +0,0 @@
-module Rack
- module Const
- RACK_VERSION = 'rack.version'.freeze
- RACK_INPUT = 'rack.input'.freeze
- RACK_ERRORS = 'rack.errors'.freeze
- RACK_MULTITHREAD = 'rack.multithread'.freeze
- RACK_MULTIPROCESS = 'rack.multiprocess'.freeze
- RACK_RUN_ONCE = 'rack.run_once'.freeze
- RACK_URL_SCHEME = 'rack.url_scheme'.freeze
- RACK_SESSION = 'rack.session'.freeze
- RACK_SESSION_OPTIONS = 'rack.session.options'.freeze
-
- ENV_CONTENT_LENGTH = 'CONTENT_LENGTH'.freeze
- ENV_CONTENT_TYPE = 'CONTENT_TYPE'.freeze
- ENV_HTTPS = 'HTTPS'.freeze
- ENV_HTTP_ACCEPT_ENCODING = 'HTTP_ACCEPT_ENCODING'.freeze
- ENV_HTTP_CONTENT_LENGTH = 'HTTP_CONTENT_LENGTH'.freeze
- ENV_HTTP_CONTENT_TYPE = 'HTTP_CONTENT_TYPE'.freeze
- ENV_HTTP_COOKIE = 'HTTP_COOKIE'.freeze
- ENV_HTTP_HOST = 'HTTP_HOST'.freeze
- ENV_HTTP_IF_MODIFIED_SINCE = 'HTTP_IF_MODIFIED_SINCE'.freeze
- ENV_HTTP_IF_NONE_MATCH = 'HTTP_IF_NONE_MATCH'.freeze
- ENV_HTTP_PORT = 'HTTP_PORT'.freeze
- ENV_HTTP_REFERER = 'HTTP_REFERER'.freeze
- ENV_HTTP_VERSION = 'HTTP_VERSION'.freeze
- ENV_HTTP_X_FORWARDED_FOR = 'HTTP_X_FORWARDED_FOR'.freeze
- ENV_HTTP_X_REQUESTED_WITH = 'HTTP_X_REQUESTED_WITH'.freeze
- ENV_PATH_INFO = 'PATH_INFO'.freeze
- ENV_QUERY_STRING = 'QUERY_STRING'.freeze
- ENV_REMOTE_ADDR = 'REMOTE_ADDR'.freeze
- ENV_REMOTE_USER = 'REMOTE_USER'.freeze
- ENV_REQUEST_METHOD = 'REQUEST_METHOD'.freeze
- ENV_REQUEST_PATH = 'REQUEST_PATH'.freeze
- ENV_REQUEST_URI = 'REQUEST_URI'.freeze
- ENV_SCRIPT_NAME = 'SCRIPT_NAME'.freeze
- ENV_SERVER_NAME = 'SERVER_NAME'.freeze
- ENV_SERVER_PORT = 'SERVER_PORT'.freeze
- ENV_SERVER_PROTOCOL = 'SERVER_PROTOCOL'.freeze
-
- CACHE_CONTROL = 'Cache-Control'.freeze
- CONTENT_ENCODING = 'Content-Encoding'.freeze
- CONTENT_LENGTH = 'Content-Length'.freeze
- CONTENT_TYPE = 'Content-Type'.freeze
- DELETE = 'DELETE'.freeze
- EMPTY_STRING = ''.freeze
- ETAG = 'Etag'.freeze
- GET = 'GET'.freeze
- HEAD = 'HEAD'.freeze
- LAST_MODIFIED = 'Last-Modified'.freeze
- POST = 'POST'.freeze
- PUT = 'PUT'.freeze
- SLASH = '/'.freeze
- TRANSFER_ENCODING = 'Transfer-Encoding'.freeze
- end
-end
@@ -14,13 +14,13 @@ def call(env)
headers = HeaderHash.new(headers)
if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
- !headers[Const::CONTENT_LENGTH] &&
- !headers[Const::TRANSFER_ENCODING] &&
+ !headers['Content-Length'] &&
+ !headers['Transfer-Encoding'] &&
(body.respond_to?(:to_ary) || body.respond_to?(:to_str))
body = [body] if body.respond_to?(:to_str) # rack 0.4 compat
length = body.to_ary.inject(0) { |len, part| len + bytesize(part) }
- headers[Const::CONTENT_LENGTH] = length.to_s
+ headers['Content-Length'] = length.to_s
end
[status, headers, body]
Oops, something went wrong.

0 comments on commit 71030b9

Please sign in to comment.