Skip to content

Commit

Permalink
fix(auto_source): respect headers from global config (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
gildesmarais authored Oct 25, 2024
1 parent d4e4d91 commit 3e9ba91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion helpers/auto_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
15 changes: 14 additions & 1 deletion spec/html2rss/web/helpers/auto_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3e9ba91

Please sign in to comment.