Fix #292 - ensure multivalued parameters are encoded correctly
This commit is contained in:
parent
549e4bd113
commit
81a061cb80
|
@ -167,7 +167,7 @@ module Google
|
||||||
#
|
#
|
||||||
# @param [Fixnum] status
|
# @param [Fixnum] status
|
||||||
# HTTP status code of response
|
# HTTP status code of response
|
||||||
# @param
|
# @param
|
||||||
# @param [Hurley::Header] header
|
# @param [Hurley::Header] header
|
||||||
# HTTP response headers
|
# HTTP response headers
|
||||||
# @param [String] body
|
# @param [String] body
|
||||||
|
@ -184,16 +184,16 @@ module Google
|
||||||
when 200...300
|
when 200...300
|
||||||
nil
|
nil
|
||||||
when 301, 302, 303, 307
|
when 301, 302, 303, 307
|
||||||
message ||= sprintf('Redirect to %s', header[:location])
|
message ||= sprintf('Redirect to %s', header[:location])
|
||||||
raise Google::Apis::RedirectError.new(message, status_code: status, header: header, body: body)
|
raise Google::Apis::RedirectError.new(message, status_code: status, header: header, body: body)
|
||||||
when 401
|
when 401
|
||||||
message ||= 'Unauthorized'
|
message ||= 'Unauthorized'
|
||||||
raise Google::Apis::AuthorizationError.new(message, status_code: status, header: header, body: body)
|
raise Google::Apis::AuthorizationError.new(message, status_code: status, header: header, body: body)
|
||||||
when 304, 400, 402...500
|
when 304, 400, 402...500
|
||||||
message ||= 'Invalid request'
|
message ||= 'Invalid request'
|
||||||
raise Google::Apis::ClientError.new(message, status_code: status, header: header, body: body)
|
raise Google::Apis::ClientError.new(message, status_code: status, header: header, body: body)
|
||||||
when 500...600
|
when 500...600
|
||||||
message ||= 'Server error'
|
message ||= 'Server error'
|
||||||
raise Google::Apis::ServerError.new(message, status_code: status, header: header, body: body)
|
raise Google::Apis::ServerError.new(message, status_code: status, header: header, body: body)
|
||||||
else
|
else
|
||||||
logger.warn(sprintf('Encountered unexpected status code %s', status))
|
logger.warn(sprintf('Encountered unexpected status code %s', status))
|
||||||
|
@ -254,6 +254,11 @@ module Google
|
||||||
begin
|
begin
|
||||||
logger.debug { sprintf('Sending HTTP %s %s', method, url) }
|
logger.debug { sprintf('Sending HTTP %s %s', method, url) }
|
||||||
response = client.send(method, url, body) do |req|
|
response = client.send(method, url, body) do |req|
|
||||||
|
# Temporary workaround for Hurley bug where the connection preference
|
||||||
|
# is ignored and it uses nested anyway
|
||||||
|
req.url.query_class = Hurley::Query::Flat
|
||||||
|
query.each { | k, v| req.url.query[k] = v }
|
||||||
|
# End workaround
|
||||||
apply_request_options(req)
|
apply_request_options(req)
|
||||||
end
|
end
|
||||||
logger.debug { response.status_code }
|
logger.debug { response.status_code }
|
||||||
|
|
|
@ -123,13 +123,13 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
||||||
command.options.retries = 1
|
command.options.retries = 1
|
||||||
expect { command.execute(client) }.to raise_error(Google::Apis::ServerError)
|
expect { command.execute(client) }.to raise_error(Google::Apis::ServerError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context('with retries exceeded') do
|
context('with retries exceeded') do
|
||||||
before(:example) do
|
before(:example) do
|
||||||
command.options.retries = 1
|
command.options.retries = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:err) do
|
let(:err) do
|
||||||
begin
|
begin
|
||||||
command.execute(client)
|
command.execute(client)
|
||||||
|
@ -137,13 +137,13 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
||||||
e
|
e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise error with HTTP status code' do
|
it 'should raise error with HTTP status code' do
|
||||||
expect(err.status_code).to eq 500
|
expect(err.status_code).to eq 500
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context('with callbacks') do
|
context('with callbacks') do
|
||||||
it 'should return the response body after retries' do
|
it 'should return the response body after retries' do
|
||||||
expect { |b| command.execute(client, &b) }.to yield_successive_args(
|
expect { |b| command.execute(client, &b) }.to yield_successive_args(
|
||||||
|
@ -255,4 +255,12 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
||||||
expect { |b| command.execute(client, &b) }.to yield_with_args(nil, an_instance_of(Google::Apis::ClientError))
|
expect { |b| command.execute(client, &b) }.to yield_with_args(nil, an_instance_of(Google::Apis::ClientError))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should send repeated query parameters' do
|
||||||
|
stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=1&a=2&a=3')
|
||||||
|
.to_return(status: [200, ''])
|
||||||
|
command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
||||||
|
command.query['a'] = [1,2,3]
|
||||||
|
command.execute(client)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,7 @@ RSpec.configure do |config|
|
||||||
config.capture_log_messages
|
config.capture_log_messages
|
||||||
|
|
||||||
Google::Apis.logger.level = Logger::DEBUG
|
Google::Apis.logger.level = Logger::DEBUG
|
||||||
|
WebMock::Config.instance.query_values_notation = :flat_array
|
||||||
end
|
end
|
||||||
|
|
||||||
[JsonSpec::Matchers::BeJsonEql,
|
[JsonSpec::Matchers::BeJsonEql,
|
||||||
|
@ -121,4 +122,3 @@ end
|
||||||
def run_integration_tests?
|
def run_integration_tests?
|
||||||
ENV['GOOGLE_APPLICATION_CREDENTIALS'] && ENV['GOOGLE_PROJECT_ID']
|
ENV['GOOGLE_APPLICATION_CREDENTIALS'] && ENV['GOOGLE_PROJECT_ID']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue