mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
updated to call Base#close when finished transmitting
This commit is contained in:
parent
d1a7e44638
commit
8b7927591b
2 changed files with 15 additions and 0 deletions
|
@ -62,6 +62,8 @@ module RestClient
|
|||
def execute & block
|
||||
uri = parse_url_with_auth(url)
|
||||
transmit uri, net_http_request_class(method).new(uri.request_uri, processed_headers), payload, & block
|
||||
ensure
|
||||
payload.close if payload
|
||||
end
|
||||
|
||||
# Extract the query parameters for get request and append them to the url
|
||||
|
|
|
@ -23,5 +23,18 @@ describe RestClient::Request do
|
|||
response_value.should == "foo"
|
||||
end
|
||||
|
||||
it 'closes payload if not nil' do
|
||||
test_file = File.new(File.join( File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))
|
||||
initial_count = tmp_count
|
||||
|
||||
stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
|
||||
|
||||
tmp_count.should == initial_count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def tmp_count
|
||||
Dir.glob(Dir::tmpdir + "/*").size
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue