You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-08-10 22:42:05 +02:00
Implemented more robust unicode handling.
* Immediatelly convert all args from `bytes` to `str`. * Added `Environment.stdin_encoding` and `Environment.stdout_encoding` * Allow unicode characters in HTTP headers and basic auth credentials by encoding them using UTF8 instead of latin1 (#212).
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from base64 import b64encode
|
||||
|
||||
import requests.auth
|
||||
|
||||
from .base import AuthPlugin
|
||||
@@ -8,13 +10,28 @@ class BuiltinAuthPlugin(AuthPlugin):
|
||||
package_name = '(builtin)'
|
||||
|
||||
|
||||
class HTTPBasicAuth(requests.auth.HTTPBasicAuth):
|
||||
|
||||
def __call__(self, r):
|
||||
"""
|
||||
Override username/password serialization to allow unicode.
|
||||
|
||||
See https://github.com/jkbr/httpie/issues/212
|
||||
|
||||
"""
|
||||
credentials = u'%s:%s' % (self.username, self.password)
|
||||
token = b64encode(credentials.encode('utf8')).strip()
|
||||
r.headers['Authorization'] = 'Basic %s' % token
|
||||
return r
|
||||
|
||||
|
||||
class BasicAuthPlugin(BuiltinAuthPlugin):
|
||||
|
||||
name = 'Basic HTTP auth'
|
||||
auth_type = 'basic'
|
||||
|
||||
def get_auth(self, username, password):
|
||||
return requests.auth.HTTPBasicAuth(username, password)
|
||||
return HTTPBasicAuth(username, password)
|
||||
|
||||
|
||||
class DigestAuthPlugin(BuiltinAuthPlugin):
|
||||
|
Reference in New Issue
Block a user