mirror of
https://github.com/httpie/cli.git
synced 2024-11-28 08:38:44 +02:00
Improved password prompt.
This commit is contained in:
parent
747b87c4e6
commit
94c77c9bfc
@ -31,8 +31,6 @@ from .cli import parser
|
||||
|
||||
FORM = 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
JSON = 'application/json; charset=utf-8'
|
||||
HTTP = 'http://'
|
||||
HTTPS = 'https://'
|
||||
|
||||
|
||||
def get_response(args, env):
|
||||
@ -65,15 +63,9 @@ def get_response(args, env):
|
||||
'digest': requests.auth.HTTPDigestAuth,
|
||||
}[args.auth_type](args.auth.key, args.auth.value)
|
||||
|
||||
if not (args.url.startswith(HTTP) or args.url.startswith(HTTPS)):
|
||||
scheme = HTTPS if env.progname == 'https' else HTTP
|
||||
url = scheme + args.url
|
||||
else:
|
||||
url = args.url
|
||||
|
||||
return requests.request(
|
||||
method=args.method.lower(),
|
||||
url=url,
|
||||
url=args.url,
|
||||
headers=args.headers,
|
||||
data=args.data,
|
||||
verify={'yes': True, 'no': False}.get(args.verify, args.verify),
|
||||
|
@ -16,13 +16,15 @@ except ImportError:
|
||||
OrderedDict = dict
|
||||
|
||||
from requests.structures import CaseInsensitiveDict
|
||||
from requests.compat import str
|
||||
from requests.compat import str, urlparse
|
||||
|
||||
from . import __version__
|
||||
|
||||
|
||||
HTTP_POST = 'POST'
|
||||
HTTP_GET = 'GET'
|
||||
HTTP = 'http://'
|
||||
HTTPS = 'https://'
|
||||
|
||||
|
||||
# Various separators used in args
|
||||
@ -106,9 +108,13 @@ class Parser(argparse.ArgumentParser):
|
||||
if not env.stdin_isatty:
|
||||
self._body_from_file(args, env.stdin)
|
||||
|
||||
if not (args.url.startswith(HTTP) or args.url.startswith(HTTPS)):
|
||||
scheme = HTTPS if env.progname == 'https' else HTTP
|
||||
args.url = scheme + args.url
|
||||
|
||||
if args.auth and not args.auth.has_password():
|
||||
# Stdin already read (if not a tty) so it's save to prompt.
|
||||
args.auth.prompt_password()
|
||||
args.auth.prompt_password(urlparse(args.url).netloc)
|
||||
|
||||
if args.prettify == PRETTIFY_STDOUT_TTY_ONLY:
|
||||
args.prettify = env.stdout_isatty
|
||||
@ -346,9 +352,10 @@ class AuthCredentials(KeyValue):
|
||||
def has_password(self):
|
||||
return self.value is not None
|
||||
|
||||
def prompt_password(self):
|
||||
def prompt_password(self, host):
|
||||
try:
|
||||
self.value = self._getpass("Password for user '%s': " % self.key)
|
||||
self.value = self._getpass(
|
||||
'http: password for %s@%s: ' % (self.key, host))
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
sys.stderr.write('\n')
|
||||
sys.exit(0)
|
||||
|
@ -85,6 +85,8 @@ class BaseStream(object):
|
||||
yield chunk
|
||||
|
||||
except BinarySuppressedError as e:
|
||||
if self.with_headers:
|
||||
yield b'\n'
|
||||
yield e.message
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user