Permalink
Browse files

Vendor Rack edge ( commit : 815342a8e15db564b766f209ffb1e340233f064f )

  • Loading branch information...
1 parent e70272e commit 5fb66a3abb4789b00158928efb5a83c0ad0004b6 @lifo lifo committed with jeremy May 1, 2009
Showing with 5,418 additions and 2 deletions.
  1. +6 −2 actionpack/lib/action_controller.rb
  2. +90 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack.rb
  3. +22 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/adapter/camping.rb
  4. +37 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/abstract/handler.rb
  5. +37 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/abstract/request.rb
  6. +58 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/basic.rb
  7. +124 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/digest/md5.rb
  8. +51 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/digest/nonce.rb
  9. +55 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/digest/params.rb
  10. +40 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/digest/request.rb
  11. +480 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/auth/openid.rb
  12. +63 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/builder.rb
  13. +36 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/cascade.rb
  14. +49 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/chunked.rb
  15. +61 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/commonlogger.rb
  16. +47 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/conditionalget.rb
  17. +29 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/content_length.rb
  18. +23 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/content_type.rb
  19. +96 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/deflater.rb
  20. +153 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/directory.rb
  21. +88 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/file.rb
  22. +69 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler.rb
  23. +61 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/cgi.rb
  24. +8 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/evented_mongrel.rb
  25. +88 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/fastcgi.rb
  26. +55 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/lsws.rb
  27. +84 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/mongrel.rb
  28. +59 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/scgi.rb
  29. +8 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/swiftiplied_mongrel.rb
  30. +18 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/thin.rb
  31. +67 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/handler/webrick.rb
  32. +19 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/head.rb
  33. +537 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/lint.rb
  34. +65 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/lobster.rb
  35. +16 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/lock.rb
  36. +27 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/methodoverride.rb
  37. +204 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/mime.rb
  38. +184 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/mock.rb
  39. +57 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/recursive.rb
  40. +106 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/reloader.rb
  41. +254 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/request.rb
  42. +183 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/response.rb
  43. +98 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/rewindable_input.rb
  44. +142 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/session/abstract/id.rb
  45. +91 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/session/cookie.rb
  46. +109 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/session/memcache.rb
  47. +100 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/session/pool.rb
  48. +349 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/showexceptions.rb
  49. +106 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/showstatus.rb
  50. +38 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/static.rb
  51. +55 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/urlmap.rb
  52. +516 −0 actionpack/lib/action_controller/vendor/rack-1.1.pre/rack/utils.rb
@@ -31,8 +31,12 @@
end
end
-gem 'rack', '~> 1.0.0'
-require 'rack'
+begin
+ gem 'rack', '~> 1.1.0'
+ require 'rack'
+rescue Gem::LoadError
+ require 'action_controller/vendor/rack-1.1.pre/rack'
+end
module ActionController
# TODO: Review explicit to see if they will automatically be handled by
@@ -0,0 +1,90 @@
+# Copyright (C) 2007, 2008, 2009 Christian Neukirchen <purl.org/net/chneukirchen>
+#
+# Rack is freely distributable under the terms of an MIT-style license.
+# See COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+path = File.expand_path(File.dirname(__FILE__))
+$:.unshift(path) unless $:.include?(path)
+
+
+# The Rack main module, serving as a namespace for all core Rack
+# modules and classes.
+#
+# All modules meant for use in your application are <tt>autoload</tt>ed here,
+# so it should be enough just to <tt>require rack.rb</tt> in your code.
+
+module Rack
+ # The Rack protocol version number implemented.
+ VERSION = [1,0]
+
+ # Return the Rack protocol version as a dotted string.
+ def self.version
+ VERSION.join(".")
+ end
+
+ # Return the Rack release as a dotted string.
+ def self.release
+ "1.0"
+ end
+
+ autoload :Builder, "rack/builder"
+ autoload :Cascade, "rack/cascade"
+ autoload :Chunked, "rack/chunked"
+ autoload :CommonLogger, "rack/commonlogger"
+ autoload :ConditionalGet, "rack/conditionalget"
+ autoload :ContentLength, "rack/content_length"
+ autoload :ContentType, "rack/content_type"
+ autoload :File, "rack/file"
+ autoload :Deflater, "rack/deflater"
+ autoload :Directory, "rack/directory"
+ autoload :ForwardRequest, "rack/recursive"
+ autoload :Handler, "rack/handler"
+ autoload :Head, "rack/head"
+ autoload :Lint, "rack/lint"
+ autoload :Lock, "rack/lock"
+ autoload :MethodOverride, "rack/methodoverride"
+ autoload :Mime, "rack/mime"
+ autoload :Recursive, "rack/recursive"
+ autoload :Reloader, "rack/reloader"
+ autoload :ShowExceptions, "rack/showexceptions"
+ autoload :ShowStatus, "rack/showstatus"
+ autoload :Static, "rack/static"
+ autoload :URLMap, "rack/urlmap"
+ autoload :Utils, "rack/utils"
+
+ autoload :MockRequest, "rack/mock"
+ autoload :MockResponse, "rack/mock"
+
+ autoload :Request, "rack/request"
+ autoload :Response, "rack/response"
+
+ module Auth
+ autoload :Basic, "rack/auth/basic"
+ autoload :AbstractRequest, "rack/auth/abstract/request"
+ autoload :AbstractHandler, "rack/auth/abstract/handler"
+ autoload :OpenID, "rack/auth/openid"
+ module Digest
+ autoload :MD5, "rack/auth/digest/md5"
+ autoload :Nonce, "rack/auth/digest/nonce"
+ autoload :Params, "rack/auth/digest/params"
+ autoload :Request, "rack/auth/digest/request"
+ end
+ end
+
+ module Session
+ autoload :Cookie, "rack/session/cookie"
+ autoload :Pool, "rack/session/pool"
+ autoload :Memcache, "rack/session/memcache"
+ end
+
+ # *Adapters* connect Rack with third party web frameworks.
+ #
+ # Rack includes an adapter for Camping, see README for other
+ # frameworks supporting Rack in their code bases.
+ #
+ # Refer to the submodules for framework-specific calling details.
+
+ module Adapter
+ autoload :Camping, "rack/adapter/camping"
+ end
+end
@@ -0,0 +1,22 @@
+module Rack
+ module Adapter
+ class Camping
+ def initialize(app)
+ @app = app
+ end
+
+ def call(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
+ h[k] = v.to_s
+ end
+ end
+ [controller.status, controller.headers, [controller.body.to_s]]
+ end
+ end
+ end
+end
@@ -0,0 +1,37 @@
+module Rack
+ module Auth
+ # Rack::Auth::AbstractHandler implements common authentication functionality.
+ #
+ # +realm+ should be set for all handlers.
+
+ class AbstractHandler
+
+ attr_accessor :realm
+
+ def initialize(app, realm=nil, &authenticator)
+ @app, @realm, @authenticator = app, realm, authenticator
+ end
+
+
+ private
+
+ def unauthorized(www_authenticate = challenge)
+ return [ 401,
+ { 'Content-Type' => 'text/plain',
+ 'Content-Length' => '0',
+ 'WWW-Authenticate' => www_authenticate.to_s },
+ []
+ ]
+ end
+
+ def bad_request
+ return [ 400,
+ { 'Content-Type' => 'text/plain',
+ 'Content-Length' => '0' },
+ []
+ ]
+ end
+
+ end
+ end
+end
@@ -0,0 +1,37 @@
+module Rack
+ module Auth
+ class AbstractRequest
+
+ def initialize(env)
+ @env = env
+ end
+
+ def provided?
+ !authorization_key.nil?
+ end
+
+ def parts
+ @parts ||= @env[authorization_key].split(' ', 2)
+ end
+
+ def scheme
+ @scheme ||= parts.first.downcase.to_sym
+ end
+
+ def params
+ @params ||= parts.last
+ end
+
+
+ private
+
+ AUTHORIZATION_KEYS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION']
+
+ def authorization_key
+ @authorization_key ||= AUTHORIZATION_KEYS.detect { |key| @env.has_key?(key) }
+ end
+
+ end
+
+ end
+end
@@ -0,0 +1,58 @@
+require 'rack/auth/abstract/handler'
+require 'rack/auth/abstract/request'
+
+module Rack
+ module Auth
+ # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617.
+ #
+ # Initialize with the Rack application that you want protecting,
+ # and a block that checks if a username and password pair are valid.
+ #
+ # See also: <tt>example/protectedlobster.rb</tt>
+
+ class Basic < AbstractHandler
+
+ def call(env)
+ auth = Basic::Request.new(env)
+
+ return unauthorized unless auth.provided?
+
+ return bad_request unless auth.basic?
+
+ if valid?(auth)
+ env['REMOTE_USER'] = auth.username
+
+ return @app.call(env)
+ end
+
+ unauthorized
+ end
+
+
+ private
+
+ def challenge
+ 'Basic realm="%s"' % realm
+ end
+
+ def valid?(auth)
+ @authenticator.call(*auth.credentials)
+ end
+
+ class Request < Auth::AbstractRequest
+ def basic?
+ :basic == scheme
+ end
+
+ def credentials
+ @credentials ||= params.unpack("m*").first.split(/:/, 2)
+ end
+
+ def username
+ credentials.first
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,124 @@
+require 'rack/auth/abstract/handler'
+require 'rack/auth/digest/request'
+require 'rack/auth/digest/params'
+require 'rack/auth/digest/nonce'
+require 'digest/md5'
+
+module Rack
+ module Auth
+ module Digest
+ # Rack::Auth::Digest::MD5 implements the MD5 algorithm version of
+ # HTTP Digest Authentication, as per RFC 2617.
+ #
+ # Initialize with the [Rack] application that you want protecting,
+ # and a block that looks up a plaintext password for a given username.
+ #
+ # +opaque+ needs to be set to a constant base64/hexadecimal string.
+ #
+ class MD5 < AbstractHandler
+
+ attr_accessor :opaque
+
+ attr_writer :passwords_hashed
+
+ def initialize(*args)
+ super
+ @passwords_hashed = nil
+ end
+
+ def passwords_hashed?
+ !!@passwords_hashed
+ end
+
+ def call(env)
+ auth = Request.new(env)
+
+ unless auth.provided?
+ return unauthorized
+ end
+
+ if !auth.digest? || !auth.correct_uri? || !valid_qop?(auth)
+ return bad_request
+ end
+
+ if valid?(auth)
+ if auth.nonce.stale?
+ return unauthorized(challenge(:stale => true))
+ else
+ env['REMOTE_USER'] = auth.username
+
+ return @app.call(env)
+ end
+ end
+
+ unauthorized
+ end
+
+
+ private
+
+ QOP = 'auth'.freeze
+
+ def params(hash = {})
+ Params.new do |params|
+ params['realm'] = realm
+ params['nonce'] = Nonce.new.to_s
+ params['opaque'] = H(opaque)
+ params['qop'] = QOP
+
+ hash.each { |k, v| params[k] = v }
+ end
+ end
+
+ def challenge(hash = {})
+ "Digest #{params(hash)}"
+ end
+
+ def valid?(auth)
+ valid_opaque?(auth) && valid_nonce?(auth) && valid_digest?(auth)
+ end
+
+ def valid_qop?(auth)
+ QOP == auth.qop
+ end
+
+ def valid_opaque?(auth)
+ H(opaque) == auth.opaque
+ end
+
+ def valid_nonce?(auth)
+ auth.nonce.valid?
+ end
+
+ def valid_digest?(auth)
+ digest(auth, @authenticator.call(auth.username)) == auth.response
+ end
+
+ def md5(data)
+ ::Digest::MD5.hexdigest(data)
+ end
+
+ alias :H :md5
+
+ def KD(secret, data)
+ H([secret, data] * ':')
+ end
+
+ def A1(auth, password)
+ [ auth.username, auth.realm, password ] * ':'
+ end
+
+ def A2(auth)
+ [ auth.method, auth.uri ] * ':'
+ end
+
+ def digest(auth, password)
+ password_hash = passwords_hashed? ? password : H(A1(auth, password))
+
+ KD(password_hash, [ auth.nonce, auth.nc, auth.cnonce, QOP, H(A2(auth)) ] * ':')
+ end
+
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 5fb66a3

Please sign in to comment.