From f0f6c1c0c84318520fb4c89b2e38ae701a7b7834 Mon Sep 17 00:00:00 2001 From: Lucas Luitjes Date: Fri, 27 Aug 2021 14:41:28 +0200 Subject: [PATCH] Do not consider http 304 a request failure (#126) * Do not consider http 304 a request failure. This status indicates the resource was not modified, rather than being moved. It's used for caching, and considering it a request failure means the server must disable all cache-related headers when rendering for grover. --- lib/grover/js/processor.js | 2 +- spec/grover/processor_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/grover/js/processor.js b/lib/grover/js/processor.js index 054bf56..fa4dc8f 100644 --- a/lib/grover/js/processor.js +++ b/lib/grover/js/processor.js @@ -127,7 +127,7 @@ const _processPage = (async (convertAction, urlOrHtml, options) => { const raiseOnRequestFailure = options.raiseOnRequestFailure; delete options.raiseOnRequestFailure; if (raiseOnRequestFailure) { page.on('requestfinished', (request) => { - if (request.response() && !request.response().ok() && !request.redirectChain().length > 0) { + if (request.response() && !(request.response().ok() || request.response().status() == 304) && !request.redirectChain().length > 0) { errors.push(request); } }); diff --git a/spec/grover/processor_spec.rb b/spec/grover/processor_spec.rb index d771dfa..7065543 100644 --- a/spec/grover/processor_spec.rb +++ b/spec/grover/processor_spec.rb @@ -592,6 +592,21 @@ end end + context 'when a 304 occurs it does not raise an error' do + let(:url_or_html) do + <<-HTML + + + Hey there + + + + HTML + end + + it { expect(pdf_text_content).to include 'Hey there' } + end + context 'when assets have redirects PDFs are generated successfully' do it { expect(pdf_text_content).to match "#{date} Google" } end