1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00

Default to https:// if invoked as `https'.

This commit is contained in:
Jakub Roztocil 2012-07-27 18:08:33 +02:00
parent a770d79aef
commit a8ddb8301d
5 changed files with 27 additions and 9 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ httpie.egg-info
build
*.pyc
.tox
README.html

View File

@ -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 <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
@ -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

View File

@ -5,3 +5,6 @@ HTTPie - cURL for humans.
__author__ = 'Jakub Roztocil'
__version__ = '0.2.7dev'
__licence__ = 'BSD'
CONTENT_TYPE = 'Content-Type'

View File

@ -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),

View File

@ -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