Skip processing for non-GET requests

This commit is contained in:
Stefan Wrobel 2013-08-20 13:55:47 -07:00
parent 81fb8384cb
commit 117f251ff7
3 changed files with 81 additions and 23 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
Gemfile.lock Gemfile.lock
pkg/* pkg/*
*.orig *.orig
tmp/

View File

@ -16,7 +16,7 @@ module Rack
end end
def skip_processing? def skip_processing?
!html? || chunked? || inline? || ignored? || bad_browser? !html? || chunked? || inline? || ignored? || bad_browser? || !get?
end end
def chunked? def chunked?
@ -38,6 +38,10 @@ module Rack
def html? def html?
@headers['Content-Type'] =~ %r{text/html} @headers['Content-Type'] =~ %r{text/html}
end end
def get?
@env['REQUEST_METHOD'] == 'GET'
end
end end
end end
end end

View File

@ -18,45 +18,40 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
end end
end end
describe '#bad_browser?' do describe '#ignored?' do
let(:user_agent) { described_class::BAD_USER_AGENTS.first.source }
it { should be_bad_browser }
end
context 'ignored' do
let(:options) { { :ignore => [ %r{file} ] } } let(:options) { { :ignore => [ %r{file} ] } }
context 'not root' do context 'path contains ignore pattern' do
let(:env) { { 'PATH_INFO' => '/this/file' } } let(:env) { { 'PATH_INFO' => '/this/file' } }
it { should be_ignored } it { should be_ignored }
end end
context 'root' do context 'root path' do
let(:env) { { 'PATH_INFO' => '/' } } let(:env) { { 'PATH_INFO' => '/' } }
it { should_not be_ignored } it { should_not be_ignored }
end end
end end
context 'not text/html' do describe '#chunked?' do
let(:headers) { { 'Content-Type' => 'application/pdf' } } context 'regular response' do
it { should_not be_chunked }
end
it { should_not be_html } context 'chunked response' do
let(:headers) { { 'Transfer-Encoding' => 'chunked' } }
it { should be_chunked }
end
end end
context 'chunked response' do describe '#inline?' do
let(:headers) { { 'Transfer-Encoding' => 'chunked' } } context 'inline disposition' do
let(:headers) { { 'Content-Disposition' => 'inline; filename=my_inlined_file' } }
it { should be_chunked } it { should be_inline }
end end
context 'inline disposition' do
let(:headers) { { 'Content-Disposition' => 'inline; filename=my_inlined_file' } }
it { should be_inline }
end end
describe '#ignored?' do describe '#ignored?' do
@ -73,5 +68,63 @@ describe Rack::LiveReload::ProcessingSkipAnalyzer do
it { should be_ignored } it { should be_ignored }
end end
end end
describe '#bad_browser?' do
context 'Firefox' do
it { should_not be_bad_browser }
end
context 'BAD browser' do
let(:user_agent) { described_class::BAD_USER_AGENTS.first.source }
it { should be_bad_browser }
end
end
describe '#html?' do
context 'HTML content' do
let(:headers) { { 'Content-Type' => 'text/html' } }
it { should be_html }
end
context 'PDF content' do
let(:headers) { { 'Content-Type' => 'application/pdf' } }
it { should_not be_html }
end
end
describe '#get?' do
context 'GET request' do
let(:env) { { 'REQUEST_METHOD' => 'GET' } }
it { should be_get }
end
context 'PUT request' do
let(:env) { { 'REQUEST_METHOD' => 'PUT' } }
it { should_not be_get }
end
context 'POST request' do
let(:env) { { 'REQUEST_METHOD' => 'POST' } }
it { should_not be_get }
end
context 'DELETE request' do
let(:env) { { 'REQUEST_METHOD' => 'DELETE' } }
it { should_not be_get }
end
context 'PATCH request' do
let(:env) { { 'REQUEST_METHOD' => 'PATCH' } }
it { should_not be_get }
end
end
end end