mirror of
https://github.com/httpie/cli.git
synced 2025-03-31 21:55:16 +02:00
Default to https:// if invoked as `https'.
This commit is contained in:
parent
a770d79aef
commit
a8ddb8301d
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ httpie.egg-info
|
|||||||
build
|
build
|
||||||
*.pyc
|
*.pyc
|
||||||
.tox
|
.tox
|
||||||
|
README.html
|
||||||
|
@ -29,7 +29,8 @@ to via `pip`_ (prefered)
|
|||||||
or ``easy_install``::
|
or ``easy_install``::
|
||||||
|
|
||||||
pip install -U httpie
|
pip install -U httpie
|
||||||
# easy_install pip
|
|
||||||
|
# easy_install httpie
|
||||||
|
|
||||||
Or, you can install the **development version** directly from GitHub:
|
Or, you can install the **development version** directly from GitHub:
|
||||||
|
|
||||||
@ -376,9 +377,8 @@ Changelog
|
|||||||
Authors
|
Authors
|
||||||
=======
|
=======
|
||||||
|
|
||||||
`Jakub Roztocil`_ (`@jkbrzt`_) created HTTPie and
|
`Jakub Roztocil`_ (`@jkbrzt`_) created HTTPie and `these fine people`_ have
|
||||||
`these fine people <https://github.com/jkbr/httpie/contributors>`_
|
contributed.
|
||||||
have contributed.
|
|
||||||
|
|
||||||
|
|
||||||
.. _suite of tests: https://github.com/jkbr/httpie/blob/master/tests/tests.py
|
.. _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
|
.. _Ubuntu: http://packages.ubuntu.com/httpie
|
||||||
.. _Debian: http://packages.debian.org/httpie
|
.. _Debian: http://packages.debian.org/httpie
|
||||||
.. _the repository: https://github.com/jkbr/httpie
|
.. _the repository: https://github.com/jkbr/httpie
|
||||||
|
.. _these fine people: https://github.com/jkbr/httpie/contributors
|
||||||
.. _Jakub Roztocil: http://roztocil.name
|
.. _Jakub Roztocil: http://roztocil.name
|
||||||
.. _@jkbrzt: https://twitter.com/jkbrzt
|
.. _@jkbrzt: https://twitter.com/jkbrzt
|
||||||
.. _existing issues: https://github.com/jkbr/httpie/issues?state=open
|
.. _existing issues: https://github.com/jkbr/httpie/issues?state=open
|
||||||
|
@ -5,3 +5,6 @@ HTTPie - cURL for humans.
|
|||||||
__author__ = 'Jakub Roztocil'
|
__author__ = 'Jakub Roztocil'
|
||||||
__version__ = '0.2.7dev'
|
__version__ = '0.2.7dev'
|
||||||
__licence__ = 'BSD'
|
__licence__ = 'BSD'
|
||||||
|
|
||||||
|
|
||||||
|
CONTENT_TYPE = 'Content-Type'
|
||||||
|
@ -8,6 +8,7 @@ Invocation flow:
|
|||||||
4. Write to `stdout` and exit.
|
4. Write to `stdout` and exit.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -23,8 +24,10 @@ from .input import (PRETTIFY_STDOUT_TTY_ONLY,
|
|||||||
from .cli import parser
|
from .cli import parser
|
||||||
|
|
||||||
|
|
||||||
TYPE_FORM = 'application/x-www-form-urlencoded; charset=utf-8'
|
FORM = 'application/x-www-form-urlencoded; charset=utf-8'
|
||||||
TYPE_JSON = 'application/json; charset=utf-8'
|
JSON = 'application/json; charset=utf-8'
|
||||||
|
HTTP = 'http://'
|
||||||
|
HTTPS = 'https://'
|
||||||
|
|
||||||
|
|
||||||
def get_response(args, env):
|
def get_response(args, env):
|
||||||
@ -33,7 +36,7 @@ def get_response(args, env):
|
|||||||
auto_json = args.data and not args.form
|
auto_json = args.data and not args.form
|
||||||
if args.json or auto_json:
|
if args.json or auto_json:
|
||||||
if 'Content-Type' not in args.headers:
|
if 'Content-Type' not in args.headers:
|
||||||
args.headers['Content-Type'] = TYPE_JSON
|
args.headers['Content-Type'] = JSON
|
||||||
|
|
||||||
if 'Accept' not in args.headers:
|
if 'Accept' not in args.headers:
|
||||||
# Default Accept to JSON as well.
|
# 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 not args.files and 'Content-Type' not in args.headers:
|
||||||
# If sending files, `requests` will set
|
# If sending files, `requests` will set
|
||||||
# the `Content-Type` for us.
|
# the `Content-Type` for us.
|
||||||
args.headers['Content-Type'] = TYPE_FORM
|
args.headers['Content-Type'] = FORM
|
||||||
|
|
||||||
try:
|
try:
|
||||||
credentials = None
|
credentials = None
|
||||||
@ -58,9 +61,15 @@ def get_response(args, env):
|
|||||||
'digest': requests.auth.HTTPDigestAuth,
|
'digest': requests.auth.HTTPDigestAuth,
|
||||||
}[args.auth_type](args.auth.key, args.auth.value)
|
}[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(
|
return requests.request(
|
||||||
method=args.method.lower(),
|
method=args.method.lower(),
|
||||||
url=args.url if '://' in args.url else 'http://%s' % args.url,
|
url=url,
|
||||||
headers=args.headers,
|
headers=args.headers,
|
||||||
data=args.data,
|
data=args.data,
|
||||||
verify={'yes': True, 'no': False}.get(args.verify, args.verify),
|
verify={'yes': True, 'no': False}.get(args.verify, args.verify),
|
||||||
|
@ -10,6 +10,10 @@ class Environment(object):
|
|||||||
and allows for mocking.
|
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_isatty = sys.stdin.isatty()
|
||||||
stdin = sys.stdin
|
stdin = sys.stdin
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user