Skip to content

Commit 65bf0d9

Browse files
committed
Workaround for 'undefined method closed?' error caused by ssrf_filter 1.1
Closes #2628
1 parent 9d03bcd commit 65bf0d9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/carrierwave/downloader/base.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def download(url, remote_headers = {})
3535
request = req
3636
end
3737
else
38-
response = SsrfFilter.get(uri, headers: headers, request_proc: ->(req) { request = req })
38+
response = SsrfFilter.get(uri, headers: headers, request_proc: ->(req) { request = req }) do |res|
39+
res.body # ensure to read body
40+
end
3941
end
4042
response.uri = request.uri
4143
response.value

spec/downloader/base_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@
156156
end
157157
end
158158

159+
context 'when actually downloading a file' do
160+
let(:uri) { 'https://raw.githubusercontent.com/carrierwaveuploader/carrierwave/master/spec/fixtures/test.jpg' }
161+
before { WebMock.disable! }
162+
after { WebMock.enable! }
163+
164+
it 'retrieves the body successfully' do
165+
expect(subject.download(uri).file.read).to eq 'this is stuff'
166+
end
167+
end
168+
159169
describe '#process_uri' do
160170
it "converts a URL with internationalized domain name to Punycode URI" do
161171
uri = "http://ドメイン名例.jp/#{CGI.escape(filename)}"

0 commit comments

Comments
 (0)