Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Import Config by jcrosby (Jon Crosby) into core

  • Loading branch information...
commit a1534a5d7b48812e1e67d7ff02ef53b70e3ea492 1 parent 5c4bd17
@josh josh authored
Showing with 40 additions and 0 deletions.
  1. +1 −0  lib/rack.rb
  2. +15 −0 lib/rack/config.rb
  3. +24 −0 test/spec_rack_config.rb
View
1  lib/rack.rb
@@ -28,6 +28,7 @@ def self.release
autoload :Chunked, "rack/chunked"
autoload :CommonLogger, "rack/commonlogger"
autoload :ConditionalGet, "rack/conditionalget"
+ autoload :Config, "rack/config"
autoload :ContentLength, "rack/content_length"
autoload :ContentType, "rack/content_type"
autoload :File, "rack/file"
View
15 lib/rack/config.rb
@@ -0,0 +1,15 @@
+module Rack
+ # Rack::Config modifies the environment using the block given during
+ # initialization.
+ class Config
+ def initialize(app, &block)
+ @app = app
+ @block = block
+ end
+
+ def call(env)
+ @block.call(env)
+ @app.call(env)
+ end
+ end
+end
View
24 test/spec_rack_config.rb
@@ -0,0 +1,24 @@
+require 'test/spec'
+require 'rack/mock'
+require 'rack/builder'
+require 'rack/content_length'
+require 'rack/config'
+
+context "Rack::Config" do
+
+ specify "should accept a block that modifies the environment" do
+ app = Rack::Builder.new do
+ use Rack::Lint
+ use Rack::ContentLength
+ use Rack::Config do |env|
+ env['greeting'] = 'hello'
+ end
+ run lambda { |env|
+ [200, {'Content-Type' => 'text/plain'}, [env['greeting'] || '']]
+ }
+ end
+ response = Rack::MockRequest.new(app).get('/')
+ response.body.should.equal('hello')
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.