1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Added support and tests for unicode support in sessions.

This commit is contained in:
Jakub Roztocil
2014-04-26 18:16:30 +02:00
parent e8a1c051f9
commit a3352af1d4
4 changed files with 38 additions and 13 deletions

View File

@@ -38,6 +38,15 @@ def get_response(args, config_dir):
return response
def encode_headers(headers):
# This allows for unicode headers which is non-standard but practical.
# See: https://github.com/jkbr/httpie/issues/212
return dict(
(name, value.encode('utf8') if isinstance(value, str) else value)
for name, value in headers.items()
)
def get_requests_kwargs(args):
"""Translate our `args` into `requests.request` keyword arguments."""
@@ -80,18 +89,11 @@ def get_requests_kwargs(args):
if args.certkey:
cert = (cert, args.certkey)
# This allows for unicode headers which is non-standard but practical.
# See: https://github.com/jkbr/httpie/issues/212
headers = dict(
(name, value.encode('utf8') if isinstance(value, str) else value)
for name, value in args.headers.items()
)
kwargs = {
'stream': True,
'method': args.method.lower(),
'url': args.url,
'headers': headers,
'headers': encode_headers(args.headers),
'data': args.data,
'verify': {
'yes': True,