diff --git a/httpie/core.py b/httpie/core.py index a76dcf45..9c30b279 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -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), diff --git a/httpie/input.py b/httpie/input.py index 9c524427..f818e194 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -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) diff --git a/httpie/output.py b/httpie/output.py index 160a5a9a..78ff52da 100644 --- a/httpie/output.py +++ b/httpie/output.py @@ -85,6 +85,8 @@ class BaseStream(object): yield chunk except BinarySuppressedError as e: + if self.with_headers: + yield b'\n' yield e.message