Skip to content

Commit

Permalink
Default to https:// if invoked as `https'.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbrzt committed Jul 27, 2012
1 parent a770d79 commit a8ddb83
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ httpie.egg-info
build
*.pyc
.tox
README.html
9 changes: 5 additions & 4 deletions README.rst
Expand Up @@ -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:

Expand Down Expand Up @@ -376,9 +377,8 @@ Changelog
Authors
=======

`Jakub Roztocil`_ (`@jkbrzt`_) created HTTPie and
`these fine people <https://github.com/jkbr/httpie/contributors>`_
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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions httpie/__init__.py
Expand Up @@ -5,3 +5,6 @@
__author__ = 'Jakub Roztocil'
__version__ = '0.2.7dev'
__licence__ = 'BSD'


CONTENT_TYPE = 'Content-Type'
19 changes: 14 additions & 5 deletions httpie/core.py
Expand Up @@ -8,6 +8,7 @@
4. Write to `stdout` and exit.
"""
import os
import sys
import json

Expand All @@ -23,8 +24,10 @@
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):
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions httpie/models.py
Expand Up @@ -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

Expand Down

0 comments on commit a8ddb83

Please sign in to comment.