Permalink
Browse files

Vendoring rack for now.

git-svn-id: http://svn.macosforge.org/repository/ruby/ControlTower/trunk@4065 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 0ccda8e commit 223c0580dc49162daa85a7b43542bc8b9d87bfb8 @jballanc jballanc committed May 11, 2010
Showing with 5,493 additions and 5 deletions.
  1. +5 −3 Rakefile
  2. +2 −2 lib/control_tower.rb
  3. +86 −0 lib/control_tower/vendor/rack.rb
  4. +22 −0 lib/control_tower/vendor/rack/adapter/camping.rb
  5. +37 −0 lib/control_tower/vendor/rack/auth/abstract/handler.rb
  6. +37 −0 lib/control_tower/vendor/rack/auth/abstract/request.rb
  7. +58 −0 lib/control_tower/vendor/rack/auth/basic.rb
  8. +124 −0 lib/control_tower/vendor/rack/auth/digest/md5.rb
  9. +51 −0 lib/control_tower/vendor/rack/auth/digest/nonce.rb
  10. +55 −0 lib/control_tower/vendor/rack/auth/digest/params.rb
  11. +40 −0 lib/control_tower/vendor/rack/auth/digest/request.rb
  12. +487 −0 lib/control_tower/vendor/rack/auth/openid.rb
  13. +63 −0 lib/control_tower/vendor/rack/builder.rb
  14. +41 −0 lib/control_tower/vendor/rack/cascade.rb
  15. +49 −0 lib/control_tower/vendor/rack/chunked.rb
  16. +52 −0 lib/control_tower/vendor/rack/commonlogger.rb
  17. +47 −0 lib/control_tower/vendor/rack/conditionalget.rb
  18. +29 −0 lib/control_tower/vendor/rack/content_length.rb
  19. +23 −0 lib/control_tower/vendor/rack/content_type.rb
  20. +96 −0 lib/control_tower/vendor/rack/deflater.rb
  21. +153 −0 lib/control_tower/vendor/rack/directory.rb
  22. +88 −0 lib/control_tower/vendor/rack/file.rb
  23. +69 −0 lib/control_tower/vendor/rack/handler.rb
  24. +61 −0 lib/control_tower/vendor/rack/handler/cgi.rb
  25. +8 −0 lib/control_tower/vendor/rack/handler/evented_mongrel.rb
  26. +90 −0 lib/control_tower/vendor/rack/handler/fastcgi.rb
  27. +63 −0 lib/control_tower/vendor/rack/handler/lsws.rb
  28. +91 −0 lib/control_tower/vendor/rack/handler/mongrel.rb
  29. +62 −0 lib/control_tower/vendor/rack/handler/scgi.rb
  30. +8 −0 lib/control_tower/vendor/rack/handler/swiftiplied_mongrel.rb
  31. +18 −0 lib/control_tower/vendor/rack/handler/thin.rb
  32. +71 −0 lib/control_tower/vendor/rack/handler/webrick.rb
  33. +19 −0 lib/control_tower/vendor/rack/head.rb
  34. +546 −0 lib/control_tower/vendor/rack/lint.rb
  35. +65 −0 lib/control_tower/vendor/rack/lobster.rb
  36. +16 −0 lib/control_tower/vendor/rack/lock.rb
  37. +27 −0 lib/control_tower/vendor/rack/methodoverride.rb
  38. +205 −0 lib/control_tower/vendor/rack/mime.rb
  39. +189 −0 lib/control_tower/vendor/rack/mock.rb
  40. +57 −0 lib/control_tower/vendor/rack/recursive.rb
  41. +109 −0 lib/control_tower/vendor/rack/reloader.rb
  42. +248 −0 lib/control_tower/vendor/rack/request.rb
  43. +149 −0 lib/control_tower/vendor/rack/response.rb
  44. +100 −0 lib/control_tower/vendor/rack/rewindable_input.rb
  45. +140 −0 lib/control_tower/vendor/rack/session/abstract/id.rb
  46. +90 −0 lib/control_tower/vendor/rack/session/cookie.rb
  47. +109 −0 lib/control_tower/vendor/rack/session/memcache.rb
  48. +100 −0 lib/control_tower/vendor/rack/session/pool.rb
  49. +349 −0 lib/control_tower/vendor/rack/showexceptions.rb
  50. +106 −0 lib/control_tower/vendor/rack/showstatus.rb
  51. +38 −0 lib/control_tower/vendor/rack/static.rb
  52. +55 −0 lib/control_tower/vendor/rack/urlmap.rb
  53. +590 −0 lib/control_tower/vendor/rack/utils.rb
View
@@ -14,15 +14,17 @@ GEM_SPEC = Gem::Specification.new do |spec|
details).
DESCRIPTION
spec.version = CT_VERSION
- spec.add_runtime_dependency 'rack', '>= 1.0.1'
spec.files = %w(
lib/control_tower.rb
lib/control_tower/rack_socket.rb
lib/control_tower/server.rb
- lib/rack/handler/control_tower.rb
lib/CTParser.bundle
bin/control_tower
- )
+ lib/rack/handler/control_tower.rb
+ lib/control_tower/vendor
+ lib/control_tower/vendor/rack
+ lib/control_tower/vendor/rack.rb
+ ) + Dir.glob('lib/control_tower/vendor/rack/*')
spec.executable = 'control_tower'
end
@@ -1,10 +1,10 @@
# This file is covered by the Ruby license. See COPYING for more details.
# Copyright (C) 2009-2010, Apple Inc. All rights reserved.
-require 'rubygems'
-require 'rack'
require 'socket'
require 'tempfile'
+$: << File.join(File.dirname(__FILE__), 'control_tower', 'vendor')
+require 'rack'
require File.join(File.dirname(__FILE__), 'control_tower', 'rack_socket')
require File.join(File.dirname(__FILE__), 'control_tower', 'server')
@@ -0,0 +1,86 @@
+# 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.
+
+# 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
Oops, something went wrong.

0 comments on commit 223c058

Please sign in to comment.