diff --git a/.rubocop.yml b/.rubocop.yml index 6236f1c..9153370 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,7 +23,7 @@ Metrics/BlockLength: - "**/*_spec.rb" Metrics/ClassLength: - Max: 135 + Max: 140 RSpec/ExampleLength: Max: 12 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9063c15..a7cb6f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog ## Unreleased -- None + +### Added +- (https://github.com/Studiosity/grover/pull/63) Ensure cookies from incoming request are passed to Grover via Middleware + ## [0.12.1](releases/tag/v0.12.1) - 2020-05-12 ### Fixed @@ -31,7 +34,7 @@ ## [0.10.1](releases/tag/v0.10.1) - 2020-01-13 ### Fixed -- [#39](https://github.com/Studiosity/grover/pull/39) Fix middleware thread safety issue ([@jnimety][]) +- [#39](https://github.com/Studiosity/grover/pull/39) Fix middleware thread safety issue ([@jnimety][]) ## [0.9.2](releases/tag/v0.9.2) - 2019-12-27 ### Added @@ -65,10 +68,10 @@ ## [0.7.4](releases/tag/v0.7.4) - 2019-07-09 ### Breaking change - [#18](https://github.com/Studiosity/grover/pull/18) Use `GROVER_NO_SANDBOX` for disabling sandbox ([@koenhandekyn][]) - + ## [0.7.3](releases/tag/v0.7.3) - 2019-05-23 ### Fixed -- [#14](https://github.com/Studiosity/grover/pull/14) Metadata options not included if source contained *any* line starting with `http` +- [#14](https://github.com/Studiosity/grover/pull/14) Metadata options not included if source contained *any* line starting with `http` - [#15](https://github.com/Studiosity/grover/pull/15) Add magic comment for freezing string literals ## [0.7.2](releases/tag/v0.7.2) - 2019-01-22 @@ -89,7 +92,7 @@ ### Breaking change - The `{{display_url}}` header/footer hack was removed in favour of passing the URL via `display_url` option - (for middleware/raw HTML only) + (for middleware/raw HTML only) ## [0.5.5](releases/tag/v0.5.5) - 2018-09-20 ### Fixed @@ -117,7 +120,7 @@ ## [0.4.3](releases/tag/v0.4.3) - 2018-09-10 ### Added -- Pass through flag to indicate to upstream middleware/app that Grover has interacted with the environment +- Pass through flag to indicate to upstream middleware/app that Grover has interacted with the environment ## [0.4.2](releases/tag/v0.4.2) - 2018-09-09 ### Fixed @@ -165,11 +168,11 @@ - Processor support for inline HTML (render via the URI rather than trying to `setContent`) ### Changed -- Minor refactor of middleware for readability +- Minor refactor of middleware for readability ## [0.2.0](releases/tag/v0.2.0) - 2018-08-23 ### Added -- Rack middleware for rendering upstream HTML as PDF (based heavily on PDFKit middleware) +- Rack middleware for rendering upstream HTML as PDF (based heavily on PDFKit middleware) - Allow PDF processor to handle inline HTML ### Fixed @@ -189,17 +192,17 @@ ## [0.1.0](releases/tag/v0.1.0) - 2018-08-22 ### Added - First pass at PDF processor -- Console script for expediting development +- Console script for expediting development ## [0.0.1](releases/tag/v0.0.1) - 2018-08-22 ### Added -- Initial gem framework +- Initial gem framework [@koenhandekyn]: https://github.com/koenhandekyn [@joergschiller]: https://github.com/joergschiller [@ryansmith23]: https://github.com/ryansmith23 -[@rwtaylor]: https://github.com/rwtaylor +[@rwtaylor]: https://github.com/rwtaylor [@jnimety]: https://github.com/jnimety [@willkoehler]: https://github.com/willkoehler [@Richacinas]: https://github.com/Richacinas -[@inspiredstuffs]: https://github.com/inspiredstuffs +[@inspiredstuffs]: https://github.com/inspiredstuffs diff --git a/lib/grover/middleware.rb b/lib/grover/middleware.rb index 4dc95dd..53080a4 100644 --- a/lib/grover/middleware.rb +++ b/lib/grover/middleware.rb @@ -97,9 +97,15 @@ def convert_to_pdf(grover) def create_grover_for_response(response) body = response.respond_to?(:body) ? response.body : response.join body = body.join if body.is_a?(Array) - body = HTMLPreprocessor.process body, root_url, protocol - Grover.new(body, display_url: request_url) + + options = { display_url: request_url } + cookies = Rack::Utils.parse_cookies(env).map do |name, value| + { name: name, value: value, domain: env['HTTP_HOST'] } + end + options[:cookies] = cookies if cookies.any? + + Grover.new(body, options) end def add_cover_content(grover) diff --git a/spec/grover/middleware_spec.rb b/spec/grover/middleware_spec.rb index 84f3ae0..41dcfa7 100644 --- a/spec/grover/middleware_spec.rb +++ b/spec/grover/middleware_spec.rb @@ -377,6 +377,20 @@ def request_env expect(last_response.body).to eq 'A converted PDF' end + it 'passes through cookies to Grover' do + expect(Grover).to( + receive(:new). + with( + 'Grover McGroveryface', + display_url: 'http://www.example.org/test', + cookies: [{ domain: 'www.example.org', name: 'key', value: 'value' }] + ).and_return(grover) + ) + expect(grover).to receive(:to_pdf).with(no_args).and_return 'A converted PDF' + get 'http://www.example.org/test.pdf', nil, 'HTTP_COOKIE' => 'key=value' + expect(last_response.body).to eq 'A converted PDF' + end + context 'when app configuration has PDF middleware disabled' do before { allow(Grover.configuration).to receive(:use_pdf_middleware).and_return false }