This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
forked from markevans/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added middleware_with_cache, so that we can more easily integrate int…
…o rails (in two lines)
- Loading branch information
Mark Evans
committed
Nov 14, 2009
1 parent
7168277
commit d33fa7e
Showing
7 changed files
with
97 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rack/cache' | ||
|
||
module Dragonfly | ||
class MiddlewareWithCache < Middleware | ||
|
||
def initialize(app, dragonfly_app_name, rack_cache_opts={}) | ||
super(app, dragonfly_app_name) | ||
@rack_cache_opts = { | ||
:verbose => true, | ||
:metastore => 'file:/var/cache/rack/meta', | ||
:entitystore => 'file:/var/cache/rack/body' | ||
}.merge(rack_cache_opts) | ||
end | ||
|
||
private | ||
|
||
def endpoint | ||
rack_cache_opts = @rack_cache_opts | ||
@endpoint ||= Rack::Builder.new do | ||
use Rack::Cache, rack_cache_opts | ||
run super | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,14 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require 'rack' | ||
require File.dirname(__FILE__) + '/shared_middleware_spec' | ||
|
||
describe Dragonfly::Middleware do | ||
|
||
def make_request(app, url) | ||
Rack::MockRequest.new(app).get(url) | ||
end | ||
|
||
before(:each) do | ||
@stack = Rack::Builder.new do | ||
use Dragonfly::Middleware, :images | ||
run lambda{|env| [200, {"Content-Type" => "text/html"}, ["#{env['PATH_INFO']}, #{env['QUERY_STRING']}"]] } | ||
run dummy_rack_app | ||
end | ||
end | ||
|
||
it "should continue the calling chain if the app returns a 404 for that url" do | ||
Dragonfly::App[:images].should_receive(:call).and_return( | ||
[404, {"Content-Type" => 'text/plain'}, ['Not found']] | ||
) | ||
response = make_request(@stack, 'hello.png?howare=you') | ||
response.status.should == 200 | ||
response.body.should == 'hello.png, howare=you' | ||
end | ||
|
||
it "should return as per the dragonfly app if the app returns a 200" do | ||
Dragonfly::App[:images].should_receive(:call).and_return( | ||
[200, {"Content-Type" => 'text/plain'}, ['ABCD']] | ||
) | ||
response = make_request(@stack, 'hello.png?howare=you') | ||
response.status.should == 200 | ||
response.body.should == 'ABCD' | ||
end | ||
|
||
it "should return as per the dragonfly app if the app returns a 400" do | ||
Dragonfly::App[:images].should_receive(:call).and_return( | ||
[400, {"Content-Type" => 'text/plain'}, ['ABCD']] | ||
) | ||
response = make_request(@stack, 'hello.png?howare=you') | ||
response.status.should == 400 | ||
response.body.should == 'ABCD' | ||
end | ||
it_should_behave_like 'dragonfly middleware' | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require File.dirname(__FILE__) + '/shared_middleware_spec' | ||
|
||
describe Dragonfly::MiddlewareWithCache do | ||
|
||
before(:each) do | ||
@stack = Rack::Builder.new do | ||
use Dragonfly::MiddlewareWithCache, :images | ||
run dummy_rack_app | ||
end | ||
end | ||
|
||
it_should_behave_like 'dragonfly middleware' | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
require 'rack' | ||
|
||
def dummy_rack_app | ||
lambda{|env| [200, {"Content-Type" => "text/html"}, ["#{env['PATH_INFO']}, #{env['QUERY_STRING']}"]] } | ||
end | ||
|
||
|
||
describe "dragonfly middleware", :shared => true do | ||
|
||
# REQUIRES THAT @stack and Dragonfly::App[:images] IS DEFINED | ||
|
||
def make_request(app, url) | ||
Rack::MockRequest.new(app).get(url) | ||
end | ||
|
||
it "should continue the calling chain if the app returns a 404 for that url" do | ||
Dragonfly::App[:images].should_receive(:call).and_return( | ||
[404, {"Content-Type" => 'text/plain'}, ['Not found']] | ||
) | ||
response = make_request(@stack, 'hello.png?howare=you') | ||
response.status.should == 200 | ||
response.body.should == 'hello.png, howare=you' | ||
end | ||
|
||
it "should return as per the dragonfly app if the app returns a 200" do | ||
Dragonfly::App[:images].should_receive(:call).and_return( | ||
[200, {"Content-Type" => 'text/plain'}, ['ABCD']] | ||
) | ||
response = make_request(@stack, 'hello.png?howare=you') | ||
response.status.should == 200 | ||
response.body.should == 'ABCD' | ||
end | ||
|
||
it "should return as per the dragonfly app if the app returns a 400" do | ||
Dragonfly::App[:images].should_receive(:call).and_return( | ||
[400, {"Content-Type" => 'text/plain'}, ['ABCD']] | ||
) | ||
response = make_request(@stack, 'hello.png?howare=you') | ||
response.status.should == 400 | ||
response.body.should == 'ABCD' | ||
end | ||
|
||
end |