Bugfix/issue 3723 (#3726)

* Extended request generation logic with support for serialized body content types other than Json

* Updated the Petstore Python client tests

* Fixed body content type identification for strings
This commit is contained in:
Bartek Kryza
2016-10-02 11:02:03 +02:00
committed by wing328
parent d4f9a16cf6
commit 40a1879797
2 changed files with 30 additions and 4 deletions

View File

@@ -122,12 +122,12 @@ class RESTClientObject(object):
r = self.pool_manager.request(method, url,
body=request_body,
headers=headers)
if headers['Content-Type'] == 'application/x-www-form-urlencoded':
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
r = self.pool_manager.request(method, url,
fields=post_params,
encode_multipart=False,
headers=headers)
if headers['Content-Type'] == 'multipart/form-data':
elif headers['Content-Type'] == 'multipart/form-data':
# must del headers['Content-Type'], or the correct Content-Type
# which generated by urllib3 will be overwritten.
del headers['Content-Type']
@@ -135,6 +135,19 @@ class RESTClientObject(object):
fields=post_params,
encode_multipart=True,
headers=headers)
# Pass a `string` parameter directly in the body to support
# other content types than Json when `body` argument is provided
# in serialized form
elif isinstance(body, str):
request_body = body
r = self.pool_manager.request(method, url,
body=request_body,
headers=headers)
else:
# Cannot generate the request from given parameters
msg = """Cannot prepare a request message for provided arguments.
Please check that your arguments match declared content type."""
raise ApiException(status=0, reason=msg)
# For `GET`, `HEAD`
else:
r = self.pool_manager.request(method, url,