Skip to content

Commit

Permalink
Update development dependencies (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrom authored Nov 26, 2024
1 parent e0e14ae commit b21f1df
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 69 deletions.
19 changes: 10 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ gemspec

gem 'childprocess', '~> 5.0'
gem 'combine_pdf', '~> 1.0'
gem 'mini_magick', '~> 4.12'
gem 'pdf-reader', '~> 2.11'
gem 'puma', '~> 6.4'
gem 'rack-test', '~> 1.1'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.12'
gem 'rubocop', '~> 1.43'
gem 'mini_magick', '~> 5.0'
gem 'pdf-reader', '~> 2.13'
gem 'puma', '~> 6.5'
gem 'rack-test', '~> 2.1'
gem 'rackup', '~> 2.2'
gem 'rake', '~> 13.2'
gem 'rspec', '~> 3.13'
gem 'rubocop', '~> 1.68'
gem 'rubocop-rake', '~> 0.6'
gem 'rubocop-rspec', '~> 2.18'
gem 'sinatra', '~> 3.2'
gem 'rubocop-rspec', '~> 3.2'
gem 'sinatra', '~> 4.1'
# Limit simplecov to 0.17.x due to https://github.com/codeclimate/test-reporter/issues/413
gem 'simplecov', '~> 0.17', '< 0.18'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ In respective controller's action use:
```ruby
respond_to do |format|
format.html do
response.headers['Content-Disposition'] = %(attachment; filename="lorem_ipsum.pdf")
response.headers['content-disposition'] = %(attachment; filename="lorem_ipsum.pdf")

render layout: 'pdf'
end
Expand Down
10 changes: 5 additions & 5 deletions lib/grover/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def ignore_request?
end

def html_content?(headers)
headers['Content-Type'] =~ %r{text/html|application/xhtml\+xml}
headers['content-type'] =~ %r{text/html|application/xhtml\+xml}
end

def update_response(response, headers)
Expand Down Expand Up @@ -155,11 +155,11 @@ def fetch_cover_pdf(path)

def assign_headers(headers, body, content_type)
# Do not cache results
headers.delete 'ETag'
headers.delete 'Cache-Control'
headers.delete 'etag'
headers.delete 'cache-control'

headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers['Content-Type'] = content_type
headers['content-length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers['content-type'] = content_type
end

def configure_env_for_grover_request(env)
Expand Down
107 changes: 55 additions & 52 deletions spec/grover/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

require 'spec_helper'

require 'rack/lint'
require 'rack/builder'

describe Grover::Middleware do
subject(:mock_app) do
builder = Rack::Builder.new
Expand All @@ -18,16 +21,16 @@
@request_env = env.deep_dup
response_size = 0
response.each { |part| response_size += part.length }
[200, headers.merge('Content-Length' => response_size.to_s), response]
[200, headers.merge('content-length' => response_size.to_s), response]
end
end

let(:app) { Rack::Lint.new(subject) }
let(:headers) do
{
'Content-Type' => 'text/html',
'ETag' => 'foo',
'Cache-Control' => 'max-age=2592000, public'
'content-type' => 'text/html',
'etag' => 'foo',
'cache-control' => 'max-age=2592000, public'
}
end
let(:response) { ['Grover McGroveryface'] }
Expand All @@ -39,18 +42,18 @@
context 'when requesting a PDF' do
it 'returns PDF content type' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
expect(last_response.headers['content-type']).to eq 'application/pdf'
response_size = Grover.new('Grover McGroveryface', display_url: 'http://www.example.org/test').to_pdf.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

it 'matches PDF case insensitive' do
get 'http://www.example.org/test.PDF'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
expect(last_response.headers['content-type']).to eq 'application/pdf'
response_size = Grover.new('Grover McGroveryface', display_url: 'http://www.example.org/test').to_pdf.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

context 'when `allow_file_uris` configuration option is set' do
Expand All @@ -74,18 +77,18 @@

it 'returns PNG content type' do
get 'http://www.example.org/test.png'
expect(last_response.headers['Content-Type']).to eq 'image/png'
expect(last_response.headers['content-type']).to eq 'image/png'
response_size = Grover.new('Grover McGroveryface').to_png.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

it 'matches PNG case insensitive' do
get 'http://www.example.org/test.PNG'
expect(last_response.headers['Content-Type']).to eq 'image/png'
expect(last_response.headers['content-type']).to eq 'image/png'
response_size = Grover.new('Grover McGroveryface').to_png.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

context 'when `allow_file_uris` configuration option is set' do
Expand All @@ -109,26 +112,26 @@

it 'returns JPEG content type' do
get 'http://www.example.org/test.jpeg'
expect(last_response.headers['Content-Type']).to eq 'image/jpeg'
expect(last_response.headers['content-type']).to eq 'image/jpeg'
response_size = Grover.new('Grover McGroveryface').to_jpeg.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

it 'matches JPEG case insensitive' do
get 'http://www.example.org/test.JPEG'
expect(last_response.headers['Content-Type']).to eq 'image/jpeg'
expect(last_response.headers['content-type']).to eq 'image/jpeg'
response_size = Grover.new('Grover McGroveryface').to_jpeg.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

it 'matches JPG case insensitive' do
get 'http://www.example.org/test.JPG'
expect(last_response.headers['Content-Type']).to eq 'image/jpeg'
expect(last_response.headers['content-type']).to eq 'image/jpeg'
response_size = Grover.new('Grover McGroveryface').to_jpeg.bytesize
expect(last_response.body.bytesize).to eq response_size
expect(last_response.headers['Content-Length']).to eq response_size.to_s
expect(last_response.headers['content-length']).to eq response_size.to_s
end

context 'when `allow_file_uris` configuration option is set' do
Expand All @@ -150,29 +153,29 @@
context 'when request doesnt have an extension' do
it 'returns the downstream content type' do
get 'http://www.example.org/test'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Grover McGroveryface'
expect(last_response.headers['Content-Length']).to eq '20'
expect(last_response.headers['content-length']).to eq '20'
end

context 'when `allow_file_uris` configuration option is set' do
before { allow(Grover.configuration).to receive(:allow_file_uris).and_return true }

it 'returns the downstream content and content type' do
get 'http://www.example.org/test'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Grover McGroveryface'
expect(last_response.headers['Content-Length']).to eq '20'
expect(last_response.headers['content-length']).to eq '20'
end
end
end

context 'when request has a non-PDF/PNG/JPEG extension' do
it 'returns the downstream content type' do
get 'http://www.example.org/test.html'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Grover McGroveryface'
expect(last_response.headers['Content-Length']).to eq '20'
expect(last_response.headers['content-length']).to eq '20'
end
end
end
Expand Down Expand Up @@ -335,68 +338,68 @@
context 'when requesting a PDF' do
it 'deletes the cache headers' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers).not_to have_key 'ETag'
expect(last_response.headers).not_to have_key 'Cache-Control'
expect(last_response.headers).not_to have_key 'etag'
expect(last_response.headers).not_to have_key 'cache-control'
end

context 'when app configuration has PDF middleware disabled' do
before { allow(Grover.configuration).to receive(:use_pdf_middleware).and_return false }

it 'returns the cache headers' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['ETag']).to eq 'foo'
expect(last_response.headers['Cache-Control']).to eq 'max-age=2592000, public'
expect(last_response.headers['etag']).to eq 'foo'
expect(last_response.headers['cache-control']).to eq 'max-age=2592000, public'
end
end
end

context 'when requesting a PNG' do
it 'returns the cache headers' do
get 'http://www.example.org/test.png'
expect(last_response.headers['ETag']).to eq 'foo'
expect(last_response.headers['Cache-Control']).to eq 'max-age=2592000, public'
expect(last_response.headers['etag']).to eq 'foo'
expect(last_response.headers['cache-control']).to eq 'max-age=2592000, public'
end

context 'when app configuration has PNG middleware enabled' do
before { allow(Grover.configuration).to receive(:use_png_middleware).and_return true }

it 'deletes the cache headers' do
get 'http://www.example.org/test.png'
expect(last_response.headers).not_to have_key 'ETag'
expect(last_response.headers).not_to have_key 'Cache-Control'
expect(last_response.headers).not_to have_key 'etag'
expect(last_response.headers).not_to have_key 'cache-control'
end
end
end

context 'when requesting a JPEG' do
it 'returns the cache headers' do
get 'http://www.example.org/test.jpeg'
expect(last_response.headers['ETag']).to eq 'foo'
expect(last_response.headers['Cache-Control']).to eq 'max-age=2592000, public'
expect(last_response.headers['etag']).to eq 'foo'
expect(last_response.headers['cache-control']).to eq 'max-age=2592000, public'
end

context 'when app configuration has JPEG middleware enabled' do
before { allow(Grover.configuration).to receive(:use_jpeg_middleware).and_return true }

it 'deletes the cache headers for JPEG' do
get 'http://www.example.org/test.jpeg'
expect(last_response.headers).not_to have_key 'ETag'
expect(last_response.headers).not_to have_key 'Cache-Control'
expect(last_response.headers).not_to have_key 'etag'
expect(last_response.headers).not_to have_key 'cache-control'
end

it 'deletes the cache headers for JPG' do
get 'http://www.example.org/test.jpg'
expect(last_response.headers).not_to have_key 'ETag'
expect(last_response.headers).not_to have_key 'Cache-Control'
expect(last_response.headers).not_to have_key 'etag'
expect(last_response.headers).not_to have_key 'cache-control'
end
end
end

context 'when not requesting a PDF, PNG or JPEG' do
it 'returns the cache headers' do
get 'http://www.example.org/test'
expect(last_response.headers['ETag']).to eq 'foo'
expect(last_response.headers['Cache-Control']).to eq 'max-age=2592000, public'
expect(last_response.headers['etag']).to eq 'foo'
expect(last_response.headers['cache-control']).to eq 'max-age=2592000, public'
end
end
end
Expand All @@ -407,7 +410,7 @@

it 'returns response as PDF' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
expect(last_response.headers['content-type']).to eq 'application/pdf'
expect(last_response.body.bytesize).to(
eq(Grover.new('Rackalicious', display_url: 'http://www.example.org/test').to_pdf.bytesize)
)
Expand All @@ -418,14 +421,14 @@

it 'returns response as text (original)' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Rackalicious'
end
end

it 'returns PNG response as text (original)' do
get 'http://www.example.org/test.png'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Rackalicious'
end

Expand All @@ -434,20 +437,20 @@

it 'returns response as PNG' do
get 'http://www.example.org/test.png'
expect(last_response.headers['Content-Type']).to eq 'image/png'
expect(last_response.headers['content-type']).to eq 'image/png'
expect(last_response.body.bytesize).to eq Grover.new('Rackalicious').to_png.bytesize
end
end

it 'returns JPEG response as text (original)' do
get 'http://www.example.org/test.jpeg'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Rackalicious'
end

it 'returns JPG response as text (original)' do
get 'http://www.example.org/test.jpg'
expect(last_response.headers['Content-Type']).to eq 'text/html'
expect(last_response.headers['content-type']).to eq 'text/html'
expect(last_response.body).to eq 'Rackalicious'
end

Expand All @@ -456,13 +459,13 @@

it 'returns response as JPEG' do
get 'http://www.example.org/test.jpeg'
expect(last_response.headers['Content-Type']).to eq 'image/jpeg'
expect(last_response.headers['content-type']).to eq 'image/jpeg'
expect(last_response.body.bytesize).to eq Grover.new('Rackalicious').to_jpeg.bytesize
end

it 'returns response as JPG' do
get 'http://www.example.org/test.jpg'
expect(last_response.headers['Content-Type']).to eq 'image/jpeg'
expect(last_response.headers['content-type']).to eq 'image/jpeg'
expect(last_response.body.bytesize).to eq Grover.new('Rackalicious').to_jpeg.bytesize
end
end
Expand All @@ -473,7 +476,7 @@

it 'returns response as PDF' do
get 'http://www.example.org/test.pdf'
expect(last_response.headers['Content-Type']).to eq 'application/pdf'
expect(last_response.headers['content-type']).to eq 'application/pdf'
expect(last_response.body.bytesize).to(
eq(Grover.new('Part 1Part 2', display_url: 'http://www.example.org/test').to_pdf.bytesize)
)
Expand Down Expand Up @@ -733,7 +736,7 @@
HTML
end

[200, headers.merge('Content-Length' => response.length.to_s), [response]]
[200, headers.merge('content-length' => response.length.to_s), [response]]
end
end

Expand Down Expand Up @@ -772,7 +775,7 @@
HTML
end

[200, headers.merge('Content-Length' => response.length.to_s), [response]]
[200, headers.merge('content-length' => response.length.to_s), [response]]
end
end

Expand Down Expand Up @@ -1013,7 +1016,7 @@
else 'Default page contents'
end

[200, headers.merge('Content-Length' => response.length.to_s), [response]]
[200, headers.merge('content-length' => response.length.to_s), [response]]
end
end

Expand Down
Loading

0 comments on commit b21f1df

Please sign in to comment.