diff --git a/helpers/auto_source.rb b/helpers/auto_source.rb index fbf8e1a..17af5c1 100644 --- a/helpers/auto_source.rb +++ b/helpers/auto_source.rb @@ -24,7 +24,7 @@ def self.allowed_origins = ENV.fetch('AUTO_SOURCE_ALLOWED_ORIGINS', '') # @return [RSS::Rss] def self.build_auto_source_from_encoded_url(encoded_url) url = Addressable::URI.parse Base64.urlsafe_decode64(encoded_url) - request = SsrfFilter.get(url) + request = SsrfFilter.get(url, headers: LocalConfig.global.fetch(:headers, {})) headers = request.to_hash.transform_values(&:first) auto_source = Html2rss::AutoSource.new(url, body: request.body, headers:) diff --git a/spec/html2rss/web/helpers/auto_source_spec.rb b/spec/html2rss/web/helpers/auto_source_spec.rb index 67af107..e9e6b2d 100644 --- a/spec/html2rss/web/helpers/auto_source_spec.rb +++ b/spec/html2rss/web/helpers/auto_source_spec.rb @@ -157,10 +157,23 @@ end end - let(:encoded_url) { Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web/commits/master') } + before do + allow(SsrfFilter).to receive(:get).with(any_args).and_call_original + end + + let(:url) { 'https://github.com/html2rss/html2rss-web/commits/master' } + let(:encoded_url) { Base64.urlsafe_encode64(url) } it 'returns an RSS::Rss object' do expect(feed).to be_a(RSS::Rss) end + + it 'sets headers in the http request' do + feed + expect(SsrfFilter).to have_received(:get).with(Addressable::URI.parse(url), + headers: { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' # rubocop:disable Layout/LineLength + }) + end end end