diff --git a/.gitignore b/.gitignore index cebbf384..254bf1c9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ httpie.egg-info build *.pyc .tox +README.html diff --git a/README.rst b/README.rst index 0b551a21..e08f2cb5 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,8 @@ to via `pip`_ (prefered) or ``easy_install``:: pip install -U httpie - # easy_install pip + + # easy_install httpie Or, you can install the **development version** directly from GitHub: @@ -376,9 +377,8 @@ Changelog Authors ======= -`Jakub Roztocil`_ (`@jkbrzt`_) created HTTPie and -`these fine people `_ -have contributed. +`Jakub Roztocil`_ (`@jkbrzt`_) created HTTPie and `these fine people`_ have +contributed. .. _suite of tests: https://github.com/jkbr/httpie/blob/master/tests/tests.py @@ -391,6 +391,7 @@ have contributed. .. _Ubuntu: http://packages.ubuntu.com/httpie .. _Debian: http://packages.debian.org/httpie .. _the repository: https://github.com/jkbr/httpie +.. _these fine people: https://github.com/jkbr/httpie/contributors .. _Jakub Roztocil: http://roztocil.name .. _@jkbrzt: https://twitter.com/jkbrzt .. _existing issues: https://github.com/jkbr/httpie/issues?state=open diff --git a/httpie/__init__.py b/httpie/__init__.py index 6cda0dee..d954c7ac 100644 --- a/httpie/__init__.py +++ b/httpie/__init__.py @@ -5,3 +5,6 @@ HTTPie - cURL for humans. __author__ = 'Jakub Roztocil' __version__ = '0.2.7dev' __licence__ = 'BSD' + + +CONTENT_TYPE = 'Content-Type' diff --git a/httpie/core.py b/httpie/core.py index abf9350f..52c2d3f2 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -8,6 +8,7 @@ Invocation flow: 4. Write to `stdout` and exit. """ +import os import sys import json @@ -23,8 +24,10 @@ from .input import (PRETTIFY_STDOUT_TTY_ONLY, from .cli import parser -TYPE_FORM = 'application/x-www-form-urlencoded; charset=utf-8' -TYPE_JSON = 'application/json; charset=utf-8' +FORM = 'application/x-www-form-urlencoded; charset=utf-8' +JSON = 'application/json; charset=utf-8' +HTTP = 'http://' +HTTPS = 'https://' def get_response(args, env): @@ -33,7 +36,7 @@ def get_response(args, env): auto_json = args.data and not args.form if args.json or auto_json: if 'Content-Type' not in args.headers: - args.headers['Content-Type'] = TYPE_JSON + args.headers['Content-Type'] = JSON if 'Accept' not in args.headers: # Default Accept to JSON as well. @@ -48,7 +51,7 @@ def get_response(args, env): if not args.files and 'Content-Type' not in args.headers: # If sending files, `requests` will set # the `Content-Type` for us. - args.headers['Content-Type'] = TYPE_FORM + args.headers['Content-Type'] = FORM try: credentials = None @@ -58,9 +61,15 @@ 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=args.url if '://' in args.url else 'http://%s' % args.url, + url=url, headers=args.headers, data=args.data, verify={'yes': True, 'no': False}.get(args.verify, args.verify), diff --git a/httpie/models.py b/httpie/models.py index 49cbd749..520df518 100644 --- a/httpie/models.py +++ b/httpie/models.py @@ -10,6 +10,10 @@ class Environment(object): and allows for mocking. """ + progname = os.path.basename(sys.argv[0]) + if progname not in ['http', 'https']: + progname = 'http' + stdin_isatty = sys.stdin.isatty() stdin = sys.stdin