Fix ruby httpx test (#16765)

* fix setup of body params (may be nil)

* fix httpx adapter issues

treating DNS resolution errors as ConnectionFailed; removing multipart header set by the openapi-generated code, as it does not contain boundary, and interferes with the generation from httpx, which appropriately deals with mime-types already
This commit is contained in:
Tiago
2023-10-10 04:31:08 +01:00
committed by GitHub
parent 23c5db602f
commit 3e9dba01ee
4 changed files with 21 additions and 36 deletions

View File

@@ -65,7 +65,7 @@ module OpenapiClient
Net::HTTP::STATUS_CODES.fetch(response.status, "HTTP Error (#{response.status})")
rescue HTTPX::TimeoutError
fail ApiError.new('Connection timed out')
rescue HTTPX::ConnectionError
rescue HTTPX::ConnectionError, HTTPX::ResolveError
fail ApiError.new('Connection failed')
end
@@ -100,13 +100,11 @@ module OpenapiClient
if config.debugging
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
end
else
body_params = {}
end
req_opts = {
:headers => HTTPX::Headers.new(header_params),
**body_params
:headers => HTTPX::Headers.new(header_params)
}
req_opts.merge!(body_params) if body_params
req_opts[:params] = query_params if query_params && !query_params.empty?
session.request(http_method, url, **req_opts)
end
@@ -121,14 +119,11 @@ module OpenapiClient
# http form
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
header_params['Content-Type'] == 'multipart/form-data'
data = { form: form_params }
header_params.delete('Content-Type') # httpx takes care of this
{ form: form_params }
elsif body
data = body.is_a?(String) ? { body: body } : { json: body }
else
data = nil
body.is_a?(String) ? { body: body } : { json: body }
end
data
end
def session