Skip to content

Commit

Permalink
Merge pull request #302 from jdb8/fix-bytestring-header-mangling-swag…
Browse files Browse the repository at this point in the history
…gerpy

Fix bytestring mangling for headers in swaggerpy
  • Loading branch information
macisamuele committed Jul 3, 2017
2 parents a80509e + 3ee09e1 commit af3ea5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion swaggerpy/client.py
Expand Up @@ -184,7 +184,7 @@ def _construct_request(self, **kwargs):
# to string. This is need to workaround
# https://github.com/requests/requests/issues/3491
_request_options['headers'] = dict(
(k, str(v))
(k, v if isinstance(v, six.binary_type) else str(v))
for k, v in six.iteritems(_request_options['headers'])
)

Expand Down
13 changes: 13 additions & 0 deletions tests/client_test.py
Expand Up @@ -199,6 +199,19 @@ def test_multiple_headers(self):
httpretty.last_request().headers[name],
)

@httpretty.activate
def test_header_bytestrings(self):
self.uut = SwaggerClient.from_resource_listing(self.resource_listing)
httpretty.register_uri(
httpretty.GET, "http://swagger.py/swagger-test/pet",
body='[]',
)

self.uut.pet.listPets(
_request_options={'headers': {b'foo': b'bar'}},
).result()
self.assertEqual('bar', httpretty.last_request().headers['foo'])

@httpretty.activate
def test_get(self):
httpretty.register_uri(
Expand Down

0 comments on commit af3ea5c

Please sign in to comment.