Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

This reverts commit 6ae0a10.
  • Loading branch information...
commit 71030b9dbea07d4e573803805ff430d52a542607 1 parent 0acfeae
@josh josh authored
Showing with 319 additions and 383 deletions.
  1. +0 −1  lib/rack.rb
  2. +3 −3 lib/rack/adapter/camping.rb
  3. +4 −4 lib/rack/auth/abstract/handler.rb
  4. +1 −1  lib/rack/auth/basic.rb
  5. +1 −1  lib/rack/auth/digest/md5.rb
  6. +2 −2 lib/rack/auth/digest/request.rb
  7. +17 −17 lib/rack/auth/openid.rb
  8. +1 −1  lib/rack/builder.rb
  9. +5 −5 lib/rack/chunked.rb
  10. +7 −7 lib/rack/commonlogger.rb
  11. +6 −6 lib/rack/conditionalget.rb
  12. +0 −55 lib/rack/constants.rb
  13. +3 −3 lib/rack/content_length.rb
  14. +1 −1  lib/rack/content_type.rb
  15. +8 −8 lib/rack/deflater.rb
  16. +5 −5 lib/rack/directory.rb
  17. +8 −8 lib/rack/file.rb
  18. +12 −12 lib/rack/handler/cgi.rb
  19. +15 −15 lib/rack/handler/fastcgi.rb
  20. +12 −12 lib/rack/handler/lsws.rb
  21. +12 −12 lib/rack/handler/mongrel.rb
  22. +14 −14 lib/rack/handler/scgi.rb
  23. +14 −14 lib/rack/handler/webrick.rb
  24. +1 −1  lib/rack/head.rb
  25. +22 −22 lib/rack/lint.rb
  26. +2 −2 lib/rack/lobster.rb
  27. +1 −1  lib/rack/lock.rb
  28. +3 −3 lib/rack/methodoverride.rb
  29. +30 −31 lib/rack/mock.rb
  30. +10 −10 lib/rack/recursive.rb
  31. +46 −54 lib/rack/request.rb
  32. +5 −5 lib/rack/response.rb
  33. +12 −12 lib/rack/session/abstract/id.rb
  34. +8 −8 lib/rack/session/cookie.rb
  35. +5 −5 lib/rack/session/memcache.rb
  36. +5 −5 lib/rack/session/pool.rb
  37. +5 −5 lib/rack/showexceptions.rb
  38. +2 −2 lib/rack/showstatus.rb
  39. +1 −1  lib/rack/static.rb
  40. +7 −6 lib/rack/urlmap.rb
  41. +3 −3 lib/rack/utils.rb
View
1  lib/rack.rb
@@ -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"
View
6 lib/rack/adapter/camping.rb
@@ -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
View
8 lib/rack/auth/abstract/handler.rb
@@ -17,8 +17,8 @@ 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 },
[]
]
@@ -26,8 +26,8 @@ def unauthorized(www_authenticate = challenge)
def bad_request
return [ 400,
- { Const::CONTENT_TYPE => 'text/plain',
- Const::CONTENT_LENGTH => '0' },
+ { 'Content-Type' => 'text/plain',
+ 'Content-Length' => '0' },
[]
]
end
View
2  lib/rack/auth/basic.rb
@@ -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
View
2  lib/rack/auth/digest/md5.rb
@@ -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
View
4 lib/rack/auth/digest/request.rb
@@ -8,7 +8,7 @@ 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?
@@ -16,7 +16,7 @@ def digest?
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
34 lib/rack/auth/openid.rb
@@ -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,7 +278,7 @@ 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.
@@ -286,7 +286,7 @@ def check(consumer, session, req)
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,7 +366,7 @@ 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
@@ -374,21 +374,21 @@ def redirect(uri)
# 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
@@ -396,7 +396,7 @@ def access_denied
# 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
2  lib/rack/builder.rb
@@ -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
10 lib/rack/chunked.rb
@@ -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
14 lib/rack/commonlogger.rb
@@ -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
12 lib/rack/conditionalget.rb
@@ -20,14 +20,14 @@ 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]
@@ -35,12 +35,12 @@ def call(env)
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
55 lib/rack/constants.rb
@@ -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
View
6 lib/rack/content_length.rb
@@ -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]
View
2  lib/rack/content_type.rb
@@ -16,7 +16,7 @@ def initialize(app, content_type = "text/html")
def call(env)
status, headers, body = @app.call(env)
headers = Utils::HeaderHash.new(headers)
- headers[Const::CONTENT_TYPE] ||= @content_type
+ headers['Content-Type'] ||= @content_type
[status, headers.to_hash, body]
end
end
View
16 lib/rack/deflater.rb
@@ -16,7 +16,7 @@ def call(env)
# Skip compressing empty entity body responses and responses with
# no-transform set.
if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
- headers[Const::CACHE_CONTROL].to_s =~ /\bno-transform\b/
+ headers['Cache-Control'].to_s =~ /\bno-transform\b/
return [status, headers, body]
end
@@ -33,20 +33,20 @@ def call(env)
case encoding
when "gzip"
- headers[Const::CONTENT_ENCODING] = "gzip"
- headers.delete(Const::CONTENT_LENGTH)
- mtime = headers.key?(Const::LAST_MODIFIED) ?
- Time.httpdate(headers[Const::LAST_MODIFIED]) : Time.now
+ headers['Content-Encoding'] = "gzip"
+ headers.delete('Content-Length')
+ mtime = headers.key?("Last-Modified") ?
+ Time.httpdate(headers["Last-Modified"]) : Time.now
[status, headers, GzipStream.new(body, mtime)]
when "deflate"
- headers[Const::CONTENT_ENCODING] = "deflate"
- headers.delete(Const::CONTENT_LENGTH)
+ headers['Content-Encoding'] = "deflate"
+ headers.delete('Content-Length')
[status, headers, DeflateStream.new(body)]
when "identity"
[status, headers, body]
when nil
message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found."
- [406, {Const::CONTENT_TYPE => "text/plain", Const::CONTENT_LENGTH => message.length.to_s}, [message]]
+ [406, {"Content-Type" => "text/plain", "Content-Length" => message.length.to_s}, [message]]
end
end
View
10 lib/rack/directory.rb
@@ -55,8 +55,8 @@ def call(env)
def _call(env)
@env = env
- @script_name = env[Const::ENV_SCRIPT_NAME]
- @path_info = Utils.unescape(env[Const::ENV_PATH_INFO])
+ @script_name = env['SCRIPT_NAME']
+ @path_info = Utils.unescape(env['PATH_INFO'])
if forbidden = check_forbidden
forbidden
@@ -71,7 +71,7 @@ def check_forbidden
body = "Forbidden\n"
size = Rack::Utils.bytesize(body)
- return [403, {Const::CONTENT_TYPE => "text/plain",Const::CONTENT_LENGTH => size.to_s}, [body]]
+ return [403, {"Content-Type" => "text/plain","Content-Length" => size.to_s}, [body]]
end
def list_directory
@@ -95,7 +95,7 @@ def list_directory
@files << [ url, basename, size, type, mtime ]
end
- return [ 200, {Const::CONTENT_TYPE=>'text/html; charset=utf-8'}, self ]
+ return [ 200, {'Content-Type'=>'text/html; charset=utf-8'}, self ]
end
def stat(node, max = 10)
@@ -123,7 +123,7 @@ def list_path
def entity_not_found
body = "Entity not found: #{@path_info}\n"
size = Rack::Utils.bytesize(body)
- return [404, {Const::CONTENT_TYPE => "text/plain", Const::CONTENT_LENGTH => size.to_s}, [body]]
+ return [404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]]
end
def each
View
16 lib/rack/file.rb
@@ -26,7 +26,7 @@ def call(env)
F = ::File
def _call(env)
- @path_info = Utils.unescape(env[Const::ENV_PATH_INFO])
+ @path_info = Utils.unescape(env["PATH_INFO"])
return forbidden if @path_info.include? ".."
@path = F.join(@root, @path_info)
@@ -44,8 +44,8 @@ def _call(env)
def forbidden
body = "Forbidden\n"
- [403, {Const::CONTENT_TYPE => "text/plain",
- Const::CONTENT_LENGTH => body.size.to_s},
+ [403, {"Content-Type" => "text/plain",
+ "Content-Length" => body.size.to_s},
[body]]
end
@@ -64,16 +64,16 @@ def serving
end
[200, {
- Const::LAST_MODIFIED => F.mtime(@path).httpdate,
- Const::CONTENT_TYPE => Mime.mime_type(F.extname(@path), 'text/plain'),
- Const::CONTENT_LENGTH => size.to_s
+ "Last-Modified" => F.mtime(@path).httpdate,
+ "Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'),
+ "Content-Length" => size.to_s
}, body]
end
def not_found
body = "File not found: #{@path_info}\n"
- [404, {Const::CONTENT_TYPE => "text/plain",
- Const::CONTENT_LENGTH => body.size.to_s},
+ [404, {"Content-Type" => "text/plain",
+ "Content-Length" => body.size.to_s},
[body]]
end
View
24 lib/rack/handler/cgi.rb
@@ -11,24 +11,24 @@ def self.serve(app)
app = ContentLength.new(app)
env = ENV.to_hash
- env.delete Const::ENV_HTTP_CONTENT_LENGTH
+ env.delete "HTTP_CONTENT_LENGTH"
- env[Const::ENV_SCRIPT_NAME] = "" if env[Const::ENV_SCRIPT_NAME] == "/"
+ env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
- env.update({Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => $stdin,
- Const::RACK_ERRORS => $stderr,
+ env.update({"rack.version" => [1,0],
+ "rack.input" => $stdin,
+ "rack.errors" => $stderr,
- Const::RACK_MULTITHREAD => false,
- Const::RACK_MULTIPROCESS => true,
- Const::RACK_RUN_ONCE => true,
+ "rack.multithread" => false,
+ "rack.multiprocess" => true,
+ "rack.run_once" => true,
- Const::RACK_URL_SCHEME => ["yes", "on", "1"].include?(ENV[Const::ENV_HTTPS]) ? "https" : "http"
+ "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
- env[Const::ENV_QUERY_STRING] ||= ""
- env[Const::ENV_HTTP_VERSION] ||= env[Const::ENV_SERVER_PROTOCOL]
- env[Const::ENV_REQUEST_PATH] ||= "/"
+ env["QUERY_STRING"] ||= ""
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+ env["REQUEST_PATH"] ||= "/"
status, headers, body = app.call(env)
begin
View
30 lib/rack/handler/fastcgi.rb
@@ -28,29 +28,29 @@ def self.serve(request, app)
app = Rack::ContentLength.new(app)
env = request.env
- env.delete Const::ENV_HTTP_CONTENT_LENGTH
+ env.delete "HTTP_CONTENT_LENGTH"
- env[Const::ENV_SCRIPT_NAME] = "" if env[Const::ENV_SCRIPT_NAME] == "/"
+ env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
rack_input = RewindableInput.new(request.in)
- env.update({Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => rack_input,
- Const::RACK_ERRORS => request.err,
+ env.update({"rack.version" => [1,0],
+ "rack.input" => rack_input,
+ "rack.errors" => request.err,
- Const::RACK_MULTITHREAD => false,
- Const::RACK_MULTIPROCESS => true,
- Const::RACK_RUN_ONCE => false,
+ "rack.multithread" => false,
+ "rack.multiprocess" => true,
+ "rack.run_once" => false,
- Const::RACK_URL_SCHEME => ["yes", "on", "1"].include?(env[Const::ENV_HTTPS]) ? "https" : "http"
+ "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
})
- env[Const::ENV_QUERY_STRING] ||= ""
- env[Const::ENV_HTTP_VERSION] ||= env[Const::ENV_SERVER_PROTOCOL]
- env[Const::ENV_REQUEST_PATH] ||= "/"
- env.delete Const::ENV_PATH_INFO if env[Const::ENV_PATH_INFO] == ""
- env.delete Const::ENV_CONTENT_TYPE if env[Const::ENV_CONTENT_TYPE] == ""
- env.delete Const::ENV_CONTENT_LENGTH if env[Const::ENV_CONTENT_LENGTH] == ""
+ env["QUERY_STRING"] ||= ""
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+ env["REQUEST_PATH"] ||= "/"
+ env.delete "PATH_INFO" if env["PATH_INFO"] == ""
+ env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
+ env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
begin
status, headers, body = app.call(env)
View
24 lib/rack/handler/lsws.rb
@@ -13,24 +13,24 @@ def self.serve(app)
app = Rack::ContentLength.new(app)
env = ENV.to_hash
- env.delete Const::ENV_HTTP_CONTENT_LENGTH
- env[Const::ENV_SCRIPT_NAME] = "" if env[Const::ENV_SCRIPT_NAME] == "/"
+ env.delete "HTTP_CONTENT_LENGTH"
+ env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
rack_input = RewindableInput.new($stdin.read.to_s)
env.update(
- Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => rack_input,
- Const::RACK_ERRORS => $stderr,
- Const::RACK_MULTITHREAD => false,
- Const::RACK_MULTIPROCESS => true,
- Const::RACK_RUN_ONCE => false,
- Const::RACK_URL_SCHEME => ["yes", "on", "1"].include?(ENV[Const::ENV_HTTPS]) ? "https" : "http"
+ "rack.version" => [1,0],
+ "rack.input" => rack_input,
+ "rack.errors" => $stderr,
+ "rack.multithread" => false,
+ "rack.multiprocess" => true,
+ "rack.run_once" => false,
+ "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
)
- env[Const::ENV_QUERY_STRING] ||= ""
- env[Const::ENV_HTTP_VERSION] ||= env[Const::ENV_SERVER_PROTOCOL]
- env[Const::ENV_REQUEST_PATH] ||= "/"
+ env["QUERY_STRING"] ||= ""
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+ env["REQUEST_PATH"] ||= "/"
status, headers, body = app.call(env)
begin
send_headers status, headers
View
24 lib/rack/handler/mongrel.rb
@@ -40,26 +40,26 @@ def initialize(app)
def process(request, response)
env = {}.replace(request.params)
- env.delete Const::ENV_HTTP_CONTENT_TYPE
- env.delete Const::ENV_HTTP_CONTENT_LENGTH
+ env.delete "HTTP_CONTENT_TYPE"
+ env.delete "HTTP_CONTENT_LENGTH"
- env[Const::ENV_SCRIPT_NAME] = "" if env[Const::ENV_SCRIPT_NAME] == "/"
+ env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
rack_input = request.body || StringIO.new('')
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
- env.update({Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => rack_input,
- Const::RACK_ERRORS => $stderr,
+ env.update({"rack.version" => [1,0],
+ "rack.input" => rack_input,
+ "rack.errors" => $stderr,
- Const::RACK_MULTITHREAD => true,
- Const::RACK_MULTIPROCESS => false, # ???
- Const::RACK_RUN_ONCE => false,
+ "rack.multithread" => true,
+ "rack.multiprocess" => false, # ???
+ "rack.run_once" => false,
- Const::RACK_URL_SCHEME => "http",
+ "rack.url_scheme" => "http",
})
- env[Const::ENV_QUERY_STRING] ||= ""
- env.delete Const::ENV_PATH_INFO if env[Const::ENV_PATH_INFO] == ""
+ env["QUERY_STRING"] ||= ""
+ env.delete "PATH_INFO" if env["PATH_INFO"] == ""
status, headers, body = @app.call(env)
View
28 lib/rack/handler/scgi.rb
@@ -25,25 +25,25 @@ def @log.error(*args); end
def process_request(request, input_body, socket)
env = {}.replace(request)
- env.delete Const::ENV_HTTP_CONTENT_TYPE
- env.delete Const::ENV_HTTP_CONTENT_LENGTH
- env[Const::ENV_REQUEST_PATH], env[Const::ENV_QUERY_STRING] = env[Const::ENV_REQUEST_URI].split('?', 2)
- env[Const::ENV_HTTP_VERSION] ||= env[Const::ENV_SERVER_PROTOCOL]
- env[Const::ENV_PATH_INFO] = env[Const::ENV_REQUEST_PATH]
- env[Const::ENV_QUERY_STRING] ||= ""
- env[Const::ENV_SCRIPT_NAME] = ""
+ env.delete "HTTP_CONTENT_TYPE"
+ env.delete "HTTP_CONTENT_LENGTH"
+ env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2)
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+ env["PATH_INFO"] = env["REQUEST_PATH"]
+ env["QUERY_STRING"] ||= ""
+ env["SCRIPT_NAME"] = ""
rack_input = StringIO.new(input_body)
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
- env.update({Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => rack_input,
- Const::RACK_ERRORS => $stderr,
- Const::RACK_MULTITHREAD => true,
- Const::RACK_MULTIPROCESS => true,
- Const::RACK_RUN_ONCE => false,
+ env.update({"rack.version" => [1,0],
+ "rack.input" => rack_input,
+ "rack.errors" => $stderr,
+ "rack.multithread" => true,
+ "rack.multiprocess" => true,
+ "rack.run_once" => false,
- Const::RACK_URL_SCHEME => ["yes", "on", "1"].include?(env[Const::ENV_HTTPS]) ? "https" : "http"
+ "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
})
status, headers, body = app.call(env)
begin
View
28 lib/rack/handler/webrick.rb
@@ -26,25 +26,25 @@ def service(req, res)
rack_input = StringIO.new(req.body.to_s)
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
- env.update({Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => rack_input,
- Const::RACK_ERRORS => $stderr,
+ env.update({"rack.version" => [1,0],
+ "rack.input" => rack_input,
+ "rack.errors" => $stderr,
- Const::RACK_MULTITHREAD => true,
- Const::RACK_MULTIPROCESS => false,
- Const::RACK_RUN_ONCE => false,
+ "rack.multithread" => true,
+ "rack.multiprocess" => false,
+ "rack.run_once" => false,
- Const::RACK_URL_SCHEME => ["yes", "on", "1"].include?(ENV[Const::ENV_HTTPS]) ? "https" : "http"
+ "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
})
- env[Const::ENV_HTTP_VERSION] ||= env[Const::ENV_SERVER_PROTOCOL]
- env[Const::ENV_QUERY_STRING] ||= ""
- env[Const::ENV_REQUEST_PATH] ||= "/"
- if env[Const::ENV_PATH_INFO] == ""
- env.delete Const::ENV_PATH_INFO
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+ env["QUERY_STRING"] ||= ""
+ env["REQUEST_PATH"] ||= "/"
+ if env["PATH_INFO"] == ""
+ env.delete "PATH_INFO"
else
- path, n = req.request_uri.path, env[Const::ENV_SCRIPT_NAME].length
- env[Const::ENV_PATH_INFO] = path[n, path.length-n]
+ path, n = req.request_uri.path, env["SCRIPT_NAME"].length
+ env["PATH_INFO"] = path[n, path.length-n]
end
status, headers, body = @app.call(env)
View
2  lib/rack/head.rb
@@ -8,7 +8,7 @@ def initialize(app)
def call(env)
status, headers, body = @app.call(env)
- if env[Const::ENV_REQUEST_METHOD] == Const::HEAD
+ if env["REQUEST_METHOD"] == "HEAD"
[status, headers, []]
else
[status, headers, body]
View
44 lib/rack/lint.rb
@@ -40,8 +40,8 @@ def _call(env)
assert("No env given") { env }
check_env env
- env[Const::RACK_INPUT] = InputWrapper.new(env[Const::RACK_INPUT])
- env[Const::RACK_ERRORS] = ErrorWrapper.new(env[Const::RACK_ERRORS])
+ env['rack.input'] = InputWrapper.new(env['rack.input'])
+ env['rack.errors'] = ErrorWrapper.new(env['rack.errors'])
## and returns an Array of exactly three values:
status, headers, @body = @app.call(env)
@@ -126,7 +126,7 @@ def check_env(env)
## <tt>rack.session</tt>:: A hash like interface for storing request session data.
## The store must implement:
- if session = env[Const::RACK_SESSION]
+ if session = env['rack.session']
## store(key, value) (aliased as []=);
assert("session #{session.inspect} must respond to store and []=") {
session.respond_to?(:store) && session.respond_to?(:[]=)
@@ -183,50 +183,50 @@ def check_env(env)
## There are the following restrictions:
## * <tt>rack.version</tt> must be an array of Integers.
- assert("rack.version must be an Array, was #{env[Const::RACK_VERSION].class}") {
- env[Const::RACK_VERSION].instance_of? Array
+ assert("rack.version must be an Array, was #{env["rack.version"].class}") {
+ env["rack.version"].instance_of? Array
}
## * <tt>rack.url_scheme</tt> must either be +http+ or +https+.
- assert("rack.url_scheme unknown: #{env[Const::RACK_URL_SCHEME].inspect}") {
- %w[http https].include? env[Const::RACK_URL_SCHEME]
+ assert("rack.url_scheme unknown: #{env["rack.url_scheme"].inspect}") {
+ %w[http https].include? env["rack.url_scheme"]
}
## * There must be a valid input stream in <tt>rack.input</tt>.
- check_input env[Const::RACK_INPUT]
+ check_input env["rack.input"]
## * There must be a valid error stream in <tt>rack.errors</tt>.
- check_error env[Const::RACK_ERRORS]
+ check_error env["rack.errors"]
## * The <tt>REQUEST_METHOD</tt> must be a valid token.
- assert("REQUEST_METHOD unknown: #{env[Const::ENV_REQUEST_METHOD]}") {
- env[Const::ENV_REQUEST_METHOD] =~ /\A[0-9A-Za-z!\#$%&'*+.^_`|~-]+\z/
+ assert("REQUEST_METHOD unknown: #{env["REQUEST_METHOD"]}") {
+ env["REQUEST_METHOD"] =~ /\A[0-9A-Za-z!\#$%&'*+.^_`|~-]+\z/
}
## * The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>
assert("SCRIPT_NAME must start with /") {
- !env.include?(Const::ENV_SCRIPT_NAME) ||
- env[Const::ENV_SCRIPT_NAME] == "" ||
- env[Const::ENV_SCRIPT_NAME] =~ /\A\//
+ !env.include?("SCRIPT_NAME") ||
+ env["SCRIPT_NAME"] == "" ||
+ env["SCRIPT_NAME"] =~ /\A\//
}
## * The <tt>PATH_INFO</tt>, if non-empty, must start with <tt>/</tt>
assert("PATH_INFO must start with /") {
- !env.include?(Const::ENV_PATH_INFO) ||
- env[Const::ENV_PATH_INFO] == "" ||
- env[Const::ENV_PATH_INFO] =~ /\A\//
+ !env.include?("PATH_INFO") ||
+ env["PATH_INFO"] == "" ||
+ env["PATH_INFO"] =~ /\A\//
}
## * The <tt>CONTENT_LENGTH</tt>, if given, must consist of digits only.
- assert("Invalid CONTENT_LENGTH: #{env[Const::ENV_CONTENT_LENGTH]}") {
- !env.include?(Const::ENV_CONTENT_LENGTH) || env[Const::ENV_CONTENT_LENGTH] =~ /\A\d+\z/
+ assert("Invalid CONTENT_LENGTH: #{env["CONTENT_LENGTH"]}") {
+ !env.include?("CONTENT_LENGTH") || env["CONTENT_LENGTH"] =~ /\A\d+\z/
}
## * One of <tt>SCRIPT_NAME</tt> or <tt>PATH_INFO</tt> must be
## set. <tt>PATH_INFO</tt> should be <tt>/</tt> if
## <tt>SCRIPT_NAME</tt> is empty.
assert("One of SCRIPT_NAME or PATH_INFO must be set (make PATH_INFO '/' if SCRIPT_NAME is empty)") {
- env[Const::ENV_SCRIPT_NAME] || env[Const::ENV_PATH_INFO]
+ env["SCRIPT_NAME"] || env["PATH_INFO"]
}
## <tt>SCRIPT_NAME</tt> never should be <tt>/</tt>, but instead be empty.
assert("SCRIPT_NAME cannot be '/', make it '' and PATH_INFO '/'") {
- env[Const::ENV_SCRIPT_NAME] != "/"
+ env["SCRIPT_NAME"] != "/"
}
end
@@ -474,7 +474,7 @@ def check_content_length(status, headers, env)
bytes += Rack::Utils.bytesize(part)
}
- if env[Const::ENV_REQUEST_METHOD] == Const::HEAD
+ if env["REQUEST_METHOD"] == "HEAD"
assert("Response body was given for HEAD request, but should be empty") {
bytes == 0
}
View
4 lib/rack/lobster.rb
@@ -12,7 +12,7 @@ class Lobster
I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
LambdaLobster = lambda { |env|
- if env[Const::ENV_QUERY_STRING].include?("flip")
+ if env["QUERY_STRING"].include?("flip")
lobster = LobsterString.split("\n").
map { |line| line.ljust(42).reverse }.
join("\n")
@@ -26,7 +26,7 @@ class Lobster
"<pre>", lobster, "</pre>",
"<a href='#{href}'>flip!</a>"]
length = content.inject(0) { |a,e| a+e.size }.to_s
- [200, {Const::CONTENT_TYPE => "text/html", Const::CONTENT_LENGTH => length}, content]
+ [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
}
def call(env)
View
2  lib/rack/lock.rb
@@ -1,6 +1,6 @@
module Rack
class Lock
- FLAG = Const::RACK_MULTITHREAD.freeze
+ FLAG = 'rack.multithread'.freeze
def initialize(app, lock = Mutex.new)
@app, @lock = app, lock
View
6 lib/rack/methodoverride.rb
@@ -10,14 +10,14 @@ def initialize(app)
end
def call(env)
- if env[Const::ENV_REQUEST_METHOD] == Const::POST
+ if env["REQUEST_METHOD"] == "POST"
req = Request.new(env)
method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
env[HTTP_METHOD_OVERRIDE_HEADER]
method = method.to_s.upcase
if HTTP_METHODS.include?(method)
- env["rack.methodoverride.original_method"] = env[Const::ENV_REQUEST_METHOD]
- env[Const::ENV_REQUEST_METHOD] = method
+ env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
+ env["REQUEST_METHOD"] = method
end
end
View
61 lib/rack/mock.rb
@@ -1,6 +1,5 @@
require 'uri'
require 'stringio'
-require 'rack/constants'
require 'rack/lint'
require 'rack/utils'
require 'rack/response'
@@ -41,24 +40,24 @@ def string
end
DEFAULT_ENV = {
- Const::RACK_VERSION => [1,0],
- Const::RACK_INPUT => StringIO.new,
- Const::RACK_ERRORS => StringIO.new,
- Const::RACK_MULTITHREAD => true,
- Const::RACK_MULTIPROCESS => true,
- Const::RACK_RUN_ONCE => false,
+ "rack.version" => [1,0],
+ "rack.input" => StringIO.new,
+ "rack.errors" => StringIO.new,
+ "rack.multithread" => true,
+ "rack.multiprocess" => true,
+ "rack.run_once" => false,
}
def initialize(app)
@app = app
end
- def get(uri, opts={}) request(Const::GET, uri, opts) end
- def post(uri, opts={}) request(Const::POST, uri, opts) end
- def put(uri, opts={}) request(Const::PUT, uri, opts) end
- def delete(uri, opts={}) request(Const::DELETE, uri, opts) end
+ def get(uri, opts={}) request("GET", uri, opts) end
+ def post(uri, opts={}) request("POST", uri, opts) end
+ def put(uri, opts={}) request("PUT", uri, opts) end
+ def delete(uri, opts={}) request("DELETE", uri, opts) end
- def request(method=Const::GET, uri="", opts={})
+ def request(method="GET", uri="", opts={})
env = self.class.env_for(uri, opts.merge(:method => method))
if opts[:lint]
@@ -67,7 +66,7 @@ def request(method=Const::GET, uri="", opts={})
app = @app
end
- errors = env[Const::RACK_ERRORS]
+ errors = env["rack.errors"]
MockResponse.new(*(app.call(env) + [errors]))
end
@@ -78,34 +77,34 @@ def self.env_for(uri="", opts={})
env = DEFAULT_ENV.dup
- env[Const::ENV_REQUEST_METHOD] = opts[:method] ? opts[:method].to_s.upcase : Const::GET
- env[Const::ENV_SERVER_NAME] = uri.host || "example.org"
- env[Const::ENV_SERVER_PORT] = uri.port ? uri.port.to_s : "80"
- env[Const::ENV_QUERY_STRING] = uri.query.to_s
- env[Const::ENV_PATH_INFO] = (!uri.path || uri.path.empty?) ? "/" : uri.path
- env[Const::RACK_URL_SCHEME] = uri.scheme || "http"
- env[Const::ENV_HTTPS] = env[Const::RACK_URL_SCHEME] == "https" ? "on" : "off"
+ env["REQUEST_METHOD"] = opts[:method] ? opts[:method].to_s.upcase : "GET"
+ env["SERVER_NAME"] = uri.host || "example.org"
+ env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
+ env["QUERY_STRING"] = uri.query.to_s
+ env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path
+ env["rack.url_scheme"] = uri.scheme || "http"
+ env["HTTPS"] = env["rack.url_scheme"] == "https" ? "on" : "off"
- env[Const::ENV_SCRIPT_NAME] = opts[:script_name] || ""
+ env["SCRIPT_NAME"] = opts[:script_name] || ""
if opts[:fatal]
- env[Const::RACK_ERRORS] = FatalWarner.new
+ env["rack.errors"] = FatalWarner.new
else
- env[Const::RACK_ERRORS] = StringIO.new
+ env["rack.errors"] = StringIO.new
end
if params = opts[:params]
- if env[Const::ENV_REQUEST_METHOD] == Const::GET
+ if env["REQUEST_METHOD"] == "GET"
params = Utils.parse_nested_query(params) if params.is_a?(String)
- params.update(Utils.parse_nested_query(env[Const::ENV_QUERY_STRING]))
- env[Const::ENV_QUERY_STRING] = Utils.build_nested_query(params)
+ params.update(Utils.parse_nested_query(env["QUERY_STRING"]))
+ env["QUERY_STRING"] = Utils.build_nested_query(params)
elsif !opts.has_key?(:input)
- opts[Const::ENV_CONTENT_TYPE] = "application/x-www-form-urlencoded"
+ opts["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
if params.is_a?(Hash)
if data = Utils::Multipart.build_multipart(params)
opts[:input] = data
- opts[Const::ENV_CONTENT_LENGTH] ||= data.length.to_s
- opts[Const::ENV_CONTENT_TYPE] = "multipart/form-data; boundary=#{Utils::Multipart::MULTIPART_BOUNDARY}"
+ opts["CONTENT_LENGTH"] ||= data.length.to_s
+ opts["CONTENT_TYPE"] = "multipart/form-data; boundary=#{Utils::Multipart::MULTIPART_BOUNDARY}"
else
opts[:input] = Utils.build_nested_query(params)
end
@@ -125,9 +124,9 @@ def self.env_for(uri="", opts={})
end
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
- env[Const::RACK_INPUT] = rack_input
+ env['rack.input'] = rack_input
- env[Const::ENV_CONTENT_LENGTH] ||= env[Const::RACK_INPUT].length.to_s
+ env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s
opts.each { |field, value|
env[field] = value if String === field
View
20 lib/rack/recursive.rb
@@ -14,11 +14,11 @@ def initialize(url, env={})
@url = URI(url)
@env = env
- @env[Const::ENV_PATH_INFO] = @url.path
- @env[Const::ENV_QUERY_STRING] = @url.query if @url.query
- @env[Const::ENV_HTTP_HOST] = @url.host if @url.host
- @env[Const::ENV_HTTP_PORT] = @url.port if @url.port
- @env[Const::RACK_URL_SCHEME] = @url.scheme if @url.scheme
+ @env["PATH_INFO"] = @url.path
+ @env["QUERY_STRING"] = @url.query if @url.query
+ @env["HTTP_HOST"] = @url.host if @url.host
+ @env["HTTP_PORT"] = @url.port if @url.port
+ @env["rack.url_scheme"] = @url.scheme if @url.scheme
super "forwarding to #{url}"
end
@@ -35,7 +35,7 @@ def initialize(app)
end
def call(env)
- @script_name = env[Const::ENV_SCRIPT_NAME]
+ @script_name = env["SCRIPT_NAME"]
@app.call(env.merge('rack.recursive.include' => method(:include)))
rescue ForwardRequest => req
call(env.merge(req.env))
@@ -47,10 +47,10 @@ def include(env, path)
raise ArgumentError, "can only include below #{@script_name}, not #{path}"
end
- env = env.merge(Const::ENV_PATH_INFO => path, Const::ENV_SCRIPT_NAME => @script_name,
- Const::ENV_REQUEST_METHOD => Const::GET,
- Const::ENV_CONTENT_LENGTH => "0", Const::ENV_CONTENT_TYPE => "",
- Const::RACK_INPUT => StringIO.new(""))
+ env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name,
+ "REQUEST_METHOD" => "GET",
+ "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "",
+ "rack.input" => StringIO.new(""))
@app.call(env)
end
end
View
100 lib/rack/request.rb
@@ -21,17 +21,17 @@ def initialize(env)
@env = env
end
- def body; @env[Const::RACK_INPUT] end
- def scheme; @env[Const::RACK_URL_SCHEME] end
- def script_name; @env[Const::ENV_SCRIPT_NAME].to_s end
- def path_info; @env[Const::ENV_PATH_INFO].to_s end
- def port; @env[Const::ENV_SERVER_PORT].to_i end
- def request_method; @env[Const::ENV_REQUEST_METHOD] end
- def query_string; @env[Const::ENV_QUERY_STRING].to_s end
- def content_length; @env[Const::ENV_CONTENT_LENGTH] end
- def content_type; @env[Const::ENV_CONTENT_TYPE] end
- def session; @env[Const::RACK_SESSION] ||= {} end
- def session_options; @env[Const::RACK_SESSION_OPTIONS] ||= {} end
+ def body; @env["rack.input"] end
+ def scheme; @env["rack.url_scheme"] end
+ def script_name; @env["SCRIPT_NAME"].to_s end
+ def path_info; @env["PATH_INFO"].to_s end
+ def port; @env["SERVER_PORT"].to_i end
+ def request_method; @env["REQUEST_METHOD"] end
+ def query_string; @env["QUERY_STRING"].to_s end
+ def content_length; @env['CONTENT_LENGTH'] end
+ def content_type; @env['CONTENT_TYPE'] end
+ def session; @env['rack.session'] ||= {} end
+ def session_options; @env['rack.session.options'] ||= {} end
# The media type (type/subtype) portion of the CONTENT_TYPE header
# without any media type parameters. e.g., when CONTENT_TYPE is
@@ -65,17 +65,17 @@ def content_charset
def host
# Remove port number.
- (@env[Const::ENV_HTTP_HOST] || @env[Const::ENV_SERVER_NAME]).to_s.gsub(/:\d+\z/, '')
+ (@env["HTTP_HOST"] || @env["SERVER_NAME"]).to_s.gsub(/:\d+\z/, '')
end
- def script_name=(s); @env[Const::ENV_SCRIPT_NAME] = s.to_s end
- def path_info=(s); @env[Const::ENV_PATH_INFO] = s.to_s end
+ def script_name=(s); @env["SCRIPT_NAME"] = s.to_s end
+ def path_info=(s); @env["PATH_INFO"] = s.to_s end
- def get?; request_method == Const::GET end
- def post?; request_method == Const::POST end
- def put?; request_method == Const::PUT end
- def delete?; request_method == Const::DELETE end
- def head?; request_method == Const::HEAD end
+ def get?; request_method == "GET" end
+ def post?; request_method == "POST" end
+ def put?; request_method == "PUT" end
+ def delete?; request_method == "DELETE" end
+ def head?; request_method == "HEAD" end
# The set of form-data media-types. Requests that do not indicate
# one of the media types presents in this list will not be eligible
@@ -109,46 +109,41 @@ def parseable_data?
PARSEABLE_DATA_MEDIA_TYPES.include?(media_type)
end
- QUERY_STRING = 'rack.request.query_string'.freeze
- QUERY_HASH = 'rack.request.query_hash'.freeze
-
# Returns the data recieved in the query string.
def GET
- if @env[QUERY_STRING] == query_string
- @env[QUERY_HASH]
+ if @env["rack.request.query_string"] == query_string
+ @env["rack.request.query_hash"]
else
- @env[QUERY_STRING] = query_string
- @env[QUERY_HASH] = Utils.parse_nested_query(query_string)
+ @env["rack.request.query_string"] = query_string
+ @env["rack.request.query_hash"] =
+ Utils.parse_nested_query(query_string)
end
end
- FORM_INPUT = 'rack.request.form_input'.freeze
- FORM_HASH = 'rack.request.form_hash'.freeze
- FORM_VARS = 'rack.request.form_vars'.freeze
-
# Returns the data recieved in the request body.
#
# This method support both application/x-www-form-urlencoded and
# multipart/form-data.
def POST
- if @env[Const::RACK_INPUT].nil?
+ if @env["rack.input"].nil?
raise "Missing rack.input"
- elsif @env[FORM_INPUT].eql? @env[Const::RACK_INPUT]
- @env[FORM_HASH]
+ elsif @env["rack.request.form_input"].eql? @env["rack.input"]
+ @env["rack.request.form_hash"]
elsif form_data? || parseable_data?
- @env[FORM_INPUT] = @env[Const::RACK_INPUT]
- unless @env[FORM_HASH] = Utils::Multipart.parse_multipart(env)
- form_vars = @env[Const::RACK_INPUT].read
+ @env["rack.request.form_input"] = @env["rack.input"]
+ unless @env["rack.request.form_hash"] =
+ Utils::Multipart.parse_multipart(env)
+ form_vars = @env["rack.input"].read
# Fix for Safari Ajax postings that always append \0
form_vars.sub!(/\0\z/, '')
- @env[FORM_VARS] = form_vars
- @env[FORM_HASH] = Utils.parse_nested_query(form_vars)
+ @env["rack.request.form_vars"] = form_vars
+ @env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars)
- @env[Const::RACK_INPUT].rewind
+ @env["rack.input"].rewind
end
- @env[FORM_HASH]
+ @env["rack.request.form_hash"]
else
{}
end
@@ -178,28 +173,25 @@ def values_at(*keys)
# the referer of the client or '/'
def referer
- @env[Const::ENV_HTTP_REFERER] || '/'
+ @env['HTTP_REFERER'] || '/'
end
alias referrer referer
- COOKIE_STRING = 'rack.request.cookie_string'.freeze
- COOKIE_HASH = 'rack.request.cookie_hash'.freeze
-
def cookies
- return {} unless @env[Const::ENV_HTTP_COOKIE]
+ return {} unless @env["HTTP_COOKIE"]
- if @env[COOKIE_STRING] == @env[Const::ENV_HTTP_COOKIE]
- @env[COOKIE_HASH]
+ if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"]
+ @env["rack.request.cookie_hash"]
else
- @env[COOKIE_STRING] = @env[Const::ENV_HTTP_COOKIE]
+ @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"]
# According to RFC 2109:
# If multiple cookies satisfy the criteria above, they are ordered in
# the Cookie header such that those with more specific Path attributes
# precede those with less specific. Ordering with respect to other
# attributes (e.g., Domain) is unspecified.
- @env[COOKIE_HASH] =
- Utils.parse_query(@env[COOKIE_STRING], ';,').inject({}) {|h,(k,v)|
+ @env["rack.request.cookie_hash"] =
+ Utils.parse_query(@env["rack.request.cookie_string"], ';,').inject({}) {|h,(k,v)|
h[k] = Array === v ? v.first : v
h
}
@@ -207,7 +199,7 @@ def cookies
end
def xhr?
- @env[Const::ENV_HTTP_X_REQUESTED_WITH] == "XMLHttpRequest"
+ @env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"
end
# Tries to return a remake of the original request URL as a string.
@@ -234,7 +226,7 @@ def fullpath
end
def accept_encoding
- @env[Const::ENV_HTTP_ACCEPT_ENCODING].to_s.split(/,\s*/).map do |part|
+ @env["HTTP_ACCEPT_ENCODING"].to_s.split(/,\s*/).map do |part|
m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick
if m
@@ -246,10 +238,10 @@ def accept_encoding
end
def ip
- if addr = @env[Const::ENV_HTTP_X_FORWARDED_FOR]
+ if addr = @env['HTTP_X_FORWARDED_FOR']
addr.split(',').last.strip
else
- @env[Const::ENV_REMOTE_ADDR]
+ @env['REMOTE_ADDR']
end
end
end
View
10 lib/rack/response.rb
@@ -20,7 +20,7 @@ class Response
def initialize(body=[], status=200, header={}, &block)
@status = status
- @header = Utils::HeaderHash.new({Const::CONTENT_TYPE => "text/html"}.
+ @header = Utils::HeaderHash.new({"Content-Type" => "text/html"}.
merge(header))
@writer = lambda { |x| @body << x }
@@ -70,7 +70,7 @@ def finish(&block)
@block = block
if [204, 304].include?(status.to_i)
- header.delete Const::CONTENT_TYPE
+ header.delete "Content-Type"
[status.to_i, header.to_hash, []]
else
[status.to_i, header.to_hash, self]
@@ -93,7 +93,7 @@ def write(str)
@length += Rack::Utils.bytesize(s)
@writer.call s
- header[Const::CONTENT_LENGTH] = @length.to_s
+ header["Content-Length"] = @length.to_s
str
end
@@ -131,11 +131,11 @@ def include?(header)
end
def content_type
- headers[Const::CONTENT_TYPE]
+ headers["Content-Type"]
end
def content_length
- cl = headers[Const::CONTENT_LENGTH]
+ cl = headers["Content-Length"]
cl ? cl.to_i : cl
end
View
24 lib/rack/session/abstract/id.rb
@@ -18,7 +18,7 @@ module Abstract
#
# All parameters are optional.
# * :key determines the name of the cookie, by default it is
- # Const::RACK_SESSION
+ # 'rack.session'
# * :path, :domain, :expire_after, :secure, and :httponly set the related
# cookie options as by Rack::Response#add_cookie
# * :defer will not set a cookie in the response.
@@ -29,7 +29,7 @@ module Abstract
# id will be.
#
# These options can be set on a per request basis, at the location of
- # env[Const::RACK_SESSION_OPTIONS]. Additionally the id of the session can be
+ # env['rack.session.options']. Additionally the id of the session can be
# found within the options hash at the key :id. It is highly not
# recommended to change its value.
#
@@ -50,7 +50,7 @@ class ID
attr_reader :key, :default_options
def initialize(app, options={})
@app = app
- @key = options[:key] || Const::RACK_SESSION
+ @key = options[:key] || "rack.session"
@default_options = self.class::DEFAULT_OPTIONS.merge(options)
end
@@ -77,8 +77,8 @@ def generate_sid
# Extracts the session id from provided cookies and passes it and the
# environment to #get_session. It then sets the resulting session into
- # Const::RACK_SESSION, and places options and session metadata into
- # Const::RACK_SESSION_OPTIONS.
+ # 'rack.session', and places options and session metadata into
+ # 'rack.session.options'.
def load_session(env)
request = Rack::Request.new(env)
@@ -86,12 +86,12 @@ def load_session(env)
begin
session_id, session = get_session(env, session_id)
- env[Const::RACK_SESSION] = session
+ env['rack.session'] = session
rescue
- env[Const::RACK_SESSION] = Hash.new
+ env['rack.session'] = Hash.new
end
- env[Const::RACK_SESSION_OPTIONS] = @default_options.
+ env['rack.session.options'] = @default_options.
merge(:id => session_id)
end
@@ -101,14 +101,14 @@ def load_session(env)
# response with the session's id.
def commit_session(env, status, headers, body)
- session = env[Const::RACK_SESSION]
- options = env[Const::RACK_SESSION_OPTIONS]
+ session = env['rack.session']
+ options = env['rack.session.options']
session_id = options[:id]
if not session_id = set_session(env, session_id, session, options)
- env[Const::RACK_ERRORS].puts("Warning! #{self.class.name} failed to save session. Content dropped.")
+ env["rack.errors"].puts("Warning! #{self.class.name} failed to save session. Content dropped.")
elsif options[:defer] and not options[:renew]
- env[Const::RACK_ERRORS].puts("Defering cookie for #{session_id}") if $VERBOSE
+ env["rack.errors"].puts("Defering cookie for #{session_id}") if $VERBOSE
else
cookie = Hash.new
cookie[:value] = session_id
View
16 lib/rack/session/cookie.rb
@@ -13,7 +13,7 @@ module Session
#
# Example:
#
- # use Rack::Session::Cookie, :key => Const::RACK_SESSION,
+ # use Rack::Session::Cookie, :key => 'rack.session',
# :domain => 'foo.com',
# :path => '/',
# :expire_after => 2592000,
@@ -25,7 +25,7 @@ class Cookie
def initialize(app, options={})
@app = app
- @key = options[:key] || Const::RACK_SESSION
+ @key = options[:key] || "rack.session"
@secret = options[:secret]
@default_options = {:domain => nil,
:path => "/",
@@ -52,16 +52,16 @@ def load_session(env)
begin
session_data = session_data.unpack("m*").first
session_data = Marshal.load(session_data)
- env[Const::RACK_SESSION] = session_data
+ env["rack.session"] = session_data
rescue
- env[Const::RACK_SESSION] = Hash.new
+ env["rack.session"] = Hash.new
end
- env[Const::RACK_SESSION_OPTIONS] = @default_options.dup
+ env["rack.session.options"] = @default_options.dup
end
def commit_session(env, status, headers, body)
- session_data = Marshal.dump(env[Const::RACK_SESSION])
+ session_data = Marshal.dump(env["rack.session"])
session_data = [session_data].pack("m*")
if @secret
@@ -69,9 +69,9 @@ def commit_session(env, status, headers, body)
end
if session_data.size > (4096 - @key.size)
- env[Const::RACK_ERRORS].puts("Warning! Rack::Session::Cookie data size exceeds 4K. Content dropped.")
+ env["rack.errors"].puts("Warning! Rack::Session::Cookie data size exceeds 4K. Content dropped.")
else
- options = env[Const::RACK_SESSION_OPTIONS]
+ options = env["rack.session.options"]
cookie = Hash.new
cookie[:value] = session_data
cookie[:expires] = Time.now + options[:expire_after] unless options[:expire_after].nil?
View
10 lib/rack/session/memcache.rb
@@ -43,9 +43,9 @@ def generate_sid
def get_session(env, sid)
session = @pool.get(sid) if sid
- @mutex.lock if env[Const::RACK_MULTITHREAD]
+ @mutex.lock if env['rack.multithread']
unless sid and session
- env[Const::RACK_ERRORS].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
+ env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
session = {}
sid = generate_sid
ret = @pool.add sid, session
@@ -58,14 +58,14 @@ def get_session(env, sid)
warn $!.inspect
return [ nil, {} ]
ensure
- @mutex.unlock if env[Const::RACK_MULTITHREAD]
+ @mutex.unlock if env['rack.multithread']
end
def set_session(env, session_id, new_session, options)
expiry = options[:expire_after]
expiry = expiry.nil? ? 0 : expiry + 1
- @mutex.lock if env[Const::RACK_MULTITHREAD]
+ @mutex.lock if env['rack.multithread']
session = @pool.get(session_id) || {}
if options[:renew] or options[:drop]
@pool.delete session_id
@@ -82,7 +82,7 @@ def set_session(env, session_id, new_session, options)
warn $!.inspect
return false
ensure
- @mutex.unlock if env[Const::RACK_MULTITHREAD]
+ @mutex.unlock if env['rack.multithread']
end
private
View
10 lib/rack/session/pool.rb
@@ -43,9 +43,9 @@ def generate_sid
def get_session(env, sid)
session = @pool[sid] if sid
- @mutex.lock if env[Const::RACK_MULTITHREAD]
+ @mutex.lock if env['rack.multithread']
unless sid and session
- env[Const::RACK_ERRORS].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
+ env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
session = {}
sid = generate_sid
@pool.store sid, session
@@ -53,11 +53,11 @@ def get_session(env, sid)
session.instance_variable_set('@old', {}.merge(session))
return [sid, session]
ensure
- @mutex.unlock if env[Const::RACK_MULTITHREAD]
+ @mutex.unlock if env['rack.multithread']
end
def set_session(env, session_id, new_session, options)
- @mutex.lock if env[Const::RACK_MULTITHREAD]
+ @mutex.lock if env['rack.multithread']
session = @pool[session_id]
if options[:renew] or options[:drop]
@pool.delete session_id
@@ -73,7 +73,7 @@ def set_session(env, session_id, new_session, options)
warn "#{new_session.inspect} has been lost."
warn $!.inspect
ensure
- @mutex.unlock if env[Const::RACK_MULTITHREAD]
+ @mutex.unlock if env['rack.multithread']
end
private
View
10 lib/rack/showexceptions.rb
@@ -25,8 +25,8 @@ def call(env)
rescue StandardError, LoadError, SyntaxError => e
backtrace = pretty(env, e)
[500,
- {Const::CONTENT_TYPE => "text/html",
- Const::CONTENT_LENGTH => backtrace.join.size.to_s},
+ {"Content-Type" => "text/html",
+ "Content-Length" => backtrace.join.size.to_s},
backtrace]
end
@@ -58,9 +58,9 @@ def pretty(env, exception)
end
}.compact
- env[Const::RACK_ERRORS].puts "#{exception.class}: #{exception.message}"
- env[Const::RACK_ERRORS].puts exception.backtrace.map { |l| "\t" + l }
- env[Const::RACK_ERRORS].flush
+ env["rack.errors"].puts "#{exception.class}: #{exception.message}"
+ env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l }
+ env["rack.errors"].flush
[@template.result(binding)]
end
View
4 lib/rack/showstatus.rb
@@ -19,7 +19,7 @@ def initialize(app)
def call(env)
status, headers, body = @app.call(env)
headers = Utils::HeaderHash.new(headers)
- empty = headers[Const::CONTENT_LENGTH].to_i <= 0
+ empty = headers['Content-Length'].to_i <= 0
# client or server error, or explicit message
if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"]
@@ -28,7 +28,7 @@ def call(env)
detail = env["rack.showstatus.detail"] || message
body = @template.result(binding)
size = Rack::Utils.bytesize(body)
- [status, headers.merge(Const::CONTENT_TYPE => "text/html", Const::CONTENT_LENGTH => size.to_s), [body]]
+ [status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]]
else
[status, headers, body]
end
View
2  lib/rack/static.rb
@@ -24,7 +24,7 @@ def initialize(app, options={})
end
def call(env)
- path = env[Const::ENV_PATH_INFO]
+ path = env["PATH_INFO"]
can_serve = @urls.any? { |url| path.index(url) == 0 }
if can_serve
View
13 lib/rack/urlmap.rb
@@ -34,9 +34,9 @@ def remap(map)
end
def call(env)
- path = env[Const::ENV_PATH_INFO].to_s.squeeze("/")
- script_name = env[Const::ENV_SCRIPT_NAME]
- hHost, sName, sPort = env.values_at(Const::ENV_HTTP_HOST, Const::ENV_SERVER_NAME, Const::ENV_SERVER_PORT)
+ path = env["PATH_INFO"].to_s.squeeze("/")
+ script_name = env['SCRIPT_NAME']
+ hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT')
@mapping.each { |host, location, app|
next unless (hHost == host || sName == host \
|| (host.nil? && (hHost == sName || hHost == sName+':'+sPort)))
@@ -45,10 +45,11 @@ def call(env)
return app.call(
env.merge(
- Const::ENV_SCRIPT_NAME => (script_name + location),
- Const::ENV_PATH_INFO => path[location.size..-1]))
+ 'SCRIPT_NAME' => (script_name + location),
+ 'PATH_INFO' => path[location.size..-1]))
}
- [404, {Const::CONTENT_TYPE => "text/plain"}, ["Not Found: #{path}"]]
+ [404, {"Content-Type" => "text/plain"}, ["Not Found: #{path}"]]
end
end
end
+
View
6 lib/rack/utils.rb
@@ -401,7 +401,7 @@ def method_missing(method_name, *args, &block) #:nodoc:
MULTIPART_BOUNDARY = "AaB03x"
def self.parse_multipart(env)
- unless env[Const::ENV_CONTENT_TYPE] =~
+ unless env['CONTENT_TYPE'] =~
%r|\Amultipart/.*boundary=\"?([^\";,]+)\"?|n
nil
else
@@ -409,8 +409,8 @@ def self.parse_multipart(env)
params = {}
buf = ""
- content_length = env[Const::ENV_CONTENT_LENGTH].to_i
- input = env[Const::RACK_INPUT]
+ content_length = env['CONTENT_LENGTH'].to_i
+ input = env['rack.input']
input.rewind
boundary_size = Utils.bytesize(boundary) + EOL.size
Please sign in to comment.
Something went wrong with that request. Please try again.