Skip to content

Commit 3e9ba91

Browse files
authored
fix(auto_source): respect headers from global config (#691)
1 parent d4e4d91 commit 3e9ba91

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

helpers/auto_source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def self.allowed_origins = ENV.fetch('AUTO_SOURCE_ALLOWED_ORIGINS', '')
2424
# @return [RSS::Rss]
2525
def self.build_auto_source_from_encoded_url(encoded_url)
2626
url = Addressable::URI.parse Base64.urlsafe_decode64(encoded_url)
27-
request = SsrfFilter.get(url)
27+
request = SsrfFilter.get(url, headers: LocalConfig.global.fetch(:headers, {}))
2828
headers = request.to_hash.transform_values(&:first)
2929

3030
auto_source = Html2rss::AutoSource.new(url, body: request.body, headers:)

spec/html2rss/web/helpers/auto_source_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,23 @@
157157
end
158158
end
159159

160-
let(:encoded_url) { Base64.urlsafe_encode64('https://github.com/html2rss/html2rss-web/commits/master') }
160+
before do
161+
allow(SsrfFilter).to receive(:get).with(any_args).and_call_original
162+
end
163+
164+
let(:url) { 'https://github.com/html2rss/html2rss-web/commits/master' }
165+
let(:encoded_url) { Base64.urlsafe_encode64(url) }
161166

162167
it 'returns an RSS::Rss object' do
163168
expect(feed).to be_a(RSS::Rss)
164169
end
170+
171+
it 'sets headers in the http request' do
172+
feed
173+
expect(SsrfFilter).to have_received(:get).with(Addressable::URI.parse(url),
174+
headers: {
175+
'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
176+
})
177+
end
165178
end
166179
end

0 commit comments

Comments
 (0)