mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Add some tests for accept_encoding behavior.
This commit is contained in:
parent
197bb96c94
commit
3e8642cd8d
2 changed files with 25 additions and 1 deletions
|
@ -2,7 +2,6 @@ require 'net/http'
|
|||
require 'openssl'
|
||||
require 'stringio'
|
||||
require 'uri'
|
||||
require 'zlib'
|
||||
|
||||
require File.dirname(__FILE__) + '/restclient/version'
|
||||
require File.dirname(__FILE__) + '/restclient/platform'
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require_relative '_lib'
|
||||
require 'json'
|
||||
|
||||
require 'zlib'
|
||||
|
||||
describe RestClient::Request do
|
||||
before(:all) do
|
||||
WebMock.disable!
|
||||
|
@ -99,5 +101,28 @@ describe RestClient::Request do
|
|||
expect(data.fetch(var)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not uncompress response when accept-encoding is set' do
|
||||
# == gzip ==
|
||||
raw = execute_httpbin('gzip', method: :get, headers: {accept_encoding: 'gzip, deflate'})
|
||||
|
||||
# check for gzip magic number
|
||||
expect(raw.body).to start_with("\x1F\x8B".b)
|
||||
|
||||
decoded = Zlib::GzipReader.new(StringIO.new(raw.body)).read
|
||||
parsed = JSON.parse(decoded)
|
||||
|
||||
expect(parsed['method']).to eq 'GET'
|
||||
expect(parsed.fetch('gzipped')).to be true
|
||||
|
||||
# == delate ==
|
||||
raw = execute_httpbin('deflate', method: :get, headers: {accept_encoding: 'gzip, deflate'})
|
||||
|
||||
decoded = Zlib::Inflate.new.inflate(raw.body)
|
||||
parsed = JSON.parse(decoded)
|
||||
|
||||
expect(parsed['method']).to eq 'GET'
|
||||
expect(parsed.fetch('deflated')).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue