diff options
author | John Thomas <thomas07@vt.edu> | 2016-07-12 08:06:19 -0700 |
---|---|---|
committer | Nobuaki Sukegawa <nsuke@apache.org> | 2016-09-26 01:42:02 +0900 |
commit | eacbd65f1d5aaae6cd2a4cdac89ffbba049f3558 (patch) | |
tree | e394d3022111fa2d2e3ec8da665131338b9db936 /lib/rb | |
parent | a400c690eb4dc79b0dd89d7f159931487c856dae (diff) | |
download | thrift-eacbd65f1d5aaae6cd2a4cdac89ffbba049f3558.tar.gz |
Ensuring that HTTP failures will clear the http transport outbuf var
This closes #1048
Diffstat (limited to 'lib/rb')
-rw-r--r-- | lib/rb/lib/thrift/transport/http_client_transport.rb | 1 | ||||
-rw-r--r-- | lib/rb/spec/http_client_spec.rb | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/rb/lib/thrift/transport/http_client_transport.rb b/lib/rb/lib/thrift/transport/http_client_transport.rb index 77ffe3569..c9c4fec8d 100644 --- a/lib/rb/lib/thrift/transport/http_client_transport.rb +++ b/lib/rb/lib/thrift/transport/http_client_transport.rb @@ -50,6 +50,7 @@ module Thrift data = resp.body data = Bytes.force_binary_encoding(data) @inbuf = StringIO.new data + ensure @outbuf = Bytes.empty_byte_buffer end end diff --git a/lib/rb/spec/http_client_spec.rb b/lib/rb/spec/http_client_spec.rb index 793fc73ab..5e8da24b2 100644 --- a/lib/rb/spec/http_client_spec.rb +++ b/lib/rb/spec/http_client_spec.rb @@ -67,6 +67,21 @@ describe 'Thrift::HTTPClientTransport' do end @client.flush end + + it 'should reset the outbuf on HTTP failures' do + @client.write "test" + + Net::HTTP.should_receive(:new).with("my.domain.com", 80).and_return do + mock("Net::HTTP").tap do |http| + http.should_receive(:use_ssl=).with(false) + http.should_receive(:post).with("/path/to/service?param=value", "test", {"Content-Type"=>"application/x-thrift"}) { raise Net::ReadTimeout } + end + end + + @client.flush rescue + @client.instance_variable_get(:@outbuf).should eq(Thrift::Bytes.empty_byte_buffer) + end + end describe 'ssl enabled' do |