Skip to content

Commit

Permalink
Merge pull request #26 from dtaniwaki/no-mark-in-redirection
Browse files Browse the repository at this point in the history
No dev mark in redirection
  • Loading branch information
dtaniwaki committed Jun 20, 2015
2 parents 318945a + 2439137 commit 8710023
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/rack/dev-mark/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(app, themes = [:title, :github_fork_ribbon])
@revision = Rack::DevMark.revision
@timestamp = Rack::DevMark.timestamp
end

def call(env)
Rack::DevMark.tmp_disabled = false

Expand All @@ -22,7 +22,8 @@ def call(env)

headers['X-Rack-Dev-Mark-Env'] = CGI.escape Rack::DevMark.env

if !Rack::DevMark.tmp_disabled && headers['Content-Type'].to_s =~ %r{\btext/html\b}i
redirect = 300 <= status.to_i && status.to_i < 400
if !redirect && !Rack::DevMark.tmp_disabled && headers['Content-Type'].to_s =~ %r{\btext/html\b}i
new_body = ''
response.each do |b|
begin
Expand Down
13 changes: 12 additions & 1 deletion spec/rack/dev-mark/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
describe Rack::DevMark::Middleware do
let(:headers) { {'Content-Type' => 'text/html; charset=utf-8'} }
let(:body) { ['response'] }
let(:status) { 200 }
let(:theme) { d = double setup: nil; allow(d).to receive(:insert_into){ |b| "#{b} dev-mark" }; d }
let(:app) { double call: [200, headers, body] }
let(:app) { double call: [status, headers, body] }
let(:env) { 'test' }
let(:revision) { 'rev' }
subject { Rack::DevMark::Middleware.new(app, theme) }
Expand Down Expand Up @@ -91,4 +92,14 @@
expect(body).to eq(["response"])
end
end
context "redirection" do
let(:status) { 302 }
let(:body) { ['<html><head></head><body></body></html>'] }
it "does not insert dev mark" do
status, headers, body = subject.call({})
expect(status).to eq(302)
expect(headers).to include('Content-Type' => 'text/html; charset=utf-8')
expect(body).to eq(['<html><head></head><body></body></html>'])
end
end
end

0 comments on commit 8710023

Please sign in to comment.