mirror of
https://github.com/httpie/cli.git
synced 2025-02-16 17:40:51 +01:00
Removed the "implicit_content_type" config option
If you used: "implicit_content_type": "form" You can achieve the the same result with: "default_options": ["--form"] If you used: "implicit_content_type": "json" Then it's the default behaviour and it can be removed. In either case HTTPie will migrate your config file on the next invocation.
This commit is contained in:
parent
5dbd104c3b
commit
20823c1702
@ -18,6 +18,8 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
|
||||
* Added ``--max-redirects`` (default 30)
|
||||
* Added ``-A`` as short name for ``--auth-type``
|
||||
* Added ``-F`` as short name for ``--follow``
|
||||
* Removed the ``"implicit_content_type" config option
|
||||
(use ``"default_options": ["--form"]`` instead)
|
||||
* Redirected ``stdout`` doesn't trigger an error anymore when ``--output FILE``
|
||||
is set
|
||||
* Changed the default ``--style`` back to ``solarized`` for better support
|
||||
|
41
README.rst
41
README.rst
@ -1230,31 +1230,32 @@ Config
|
||||
HTTPie uses a simple configuration file that contains a JSON object with the
|
||||
following keys:
|
||||
|
||||
========================= =================================================
|
||||
``__meta__`` HTTPie automatically stores some metadata here.
|
||||
Do not change.
|
||||
|
||||
``implicit_content_type`` A ``String`` specifying the implicit content type
|
||||
for request data. The default value for this
|
||||
option is ``json`` and can be changed to
|
||||
``form``.
|
||||
``__meta__``
|
||||
------------
|
||||
HTTPie automatically stores some of its metadata here. Do not change.
|
||||
|
||||
``default_options`` An ``Array`` (by default empty) of options
|
||||
that should be applied to every request.
|
||||
|
||||
For instance, you can use this option to change
|
||||
the default style and output options:
|
||||
``"default_options": ["--style=fruity", "--body"]``
|
||||
``default_options``
|
||||
-------------------
|
||||
|
||||
An ``Array`` (by default empty) of default options that should be applied to
|
||||
every invocation of HTTPie.
|
||||
|
||||
For instance, you can use this option to change the default style and output
|
||||
options: ``"default_options": ["--style=fruity", "--body"]``
|
||||
|
||||
Another useful default option is ``"--session=default"`` to make HTTPie always
|
||||
use `sessions`_.
|
||||
|
||||
Or you could change the implicit request content type from JSON to form by
|
||||
adding the ``--form``.
|
||||
|
||||
Default options from config file can be unset for a particular invocation via
|
||||
``--no-OPTION`` arguments passed on the command line (e.g., ``--no-style``
|
||||
or ``--no-session``).
|
||||
|
||||
Another useful default option is
|
||||
``"--session=default"`` to make HTTPie always
|
||||
use `sessions`_.
|
||||
|
||||
Default options from config file can be unset
|
||||
for a particular invocation via
|
||||
``--no-OPTION`` arguments passed on the
|
||||
command line (e.g., ``--no-style``
|
||||
or ``--no-session``).
|
||||
========================= =================================================
|
||||
|
||||
The default location of the configuration file is ``~/.httpie/config.json``
|
||||
|
@ -84,7 +84,6 @@ class Config(BaseConfigDict):
|
||||
about = 'HTTPie configuration file'
|
||||
|
||||
DEFAULTS = {
|
||||
'implicit_content_type': 'json',
|
||||
'default_options': []
|
||||
}
|
||||
|
||||
@ -93,5 +92,21 @@ class Config(BaseConfigDict):
|
||||
self.update(self.DEFAULTS)
|
||||
self.directory = directory
|
||||
|
||||
def load(self):
|
||||
super(Config, self).load()
|
||||
self._migrate_implicit_content_type()
|
||||
|
||||
def _get_path(self):
|
||||
return os.path.join(self.directory, self.name + '.json')
|
||||
|
||||
def _migrate_implicit_content_type(self):
|
||||
"""Migrate the removed implicit_content_type config option"""
|
||||
try:
|
||||
implicit_content_type = self.pop('implicit_content_type')
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
if implicit_content_type == 'form':
|
||||
self['default_options'].insert(0, '--form')
|
||||
self.save()
|
||||
self.load()
|
||||
|
@ -142,7 +142,6 @@ class HTTPieArgumentParser(ArgumentParser):
|
||||
|
||||
# Arguments processing and environment setup.
|
||||
self._apply_no_options(no_options)
|
||||
self._apply_config()
|
||||
self._validate_download_options()
|
||||
self._setup_standard_streams()
|
||||
self._process_output_options()
|
||||
@ -214,11 +213,6 @@ class HTTPieArgumentParser(ArgumentParser):
|
||||
self.env.stdout = self.args.output_file
|
||||
self.env.stdout_isatty = False
|
||||
|
||||
def _apply_config(self):
|
||||
if (not self.args.json
|
||||
and self.env.config.implicit_content_type == 'form'):
|
||||
self.args.form = True
|
||||
|
||||
def _process_auth(self):
|
||||
"""
|
||||
If only a username provided via --auth, then ask for a password.
|
||||
|
33
tests/test_config.py
Normal file
33
tests/test_config.py
Normal file
@ -0,0 +1,33 @@
|
||||
from utils import TestEnvironment, http
|
||||
|
||||
|
||||
def test_default_options(httpbin):
|
||||
env = TestEnvironment()
|
||||
env.config['default_options'] = ['--form']
|
||||
env.config.save()
|
||||
r = http(httpbin.url + '/post', 'foo=bar', env=env)
|
||||
assert r.json['form'] == {"foo": "bar"}
|
||||
|
||||
|
||||
def test_default_options_overwrite(httpbin):
|
||||
env = TestEnvironment()
|
||||
env.config['default_options'] = ['--form']
|
||||
env.config.save()
|
||||
r = http('--json', httpbin.url + '/post', 'foo=bar', env=env)
|
||||
assert r.json['json'] == {"foo": "bar"}
|
||||
|
||||
|
||||
def test_migrate_implicit_content_type():
|
||||
config = TestEnvironment().config
|
||||
|
||||
config['implicit_content_type'] = 'json'
|
||||
config.save()
|
||||
config.load()
|
||||
assert 'implicit_content_type' not in config
|
||||
assert not config['default_options']
|
||||
|
||||
config['implicit_content_type'] = 'form'
|
||||
config.save()
|
||||
config.load()
|
||||
assert 'implicit_content_type' not in config
|
||||
assert config['default_options'] == ['--form']
|
@ -189,13 +189,14 @@ def http(*args, **kwargs):
|
||||
stderr = env.stderr
|
||||
|
||||
args = list(args)
|
||||
extra_args = []
|
||||
if '--debug' not in args:
|
||||
if '--traceback' not in args:
|
||||
extra_args.append('--traceback')
|
||||
if not any('--timeout' in arg for arg in args):
|
||||
extra_args.append('--timeout=3')
|
||||
args = extra_args + args
|
||||
args_with_config_defaults = args + env.config.default_options
|
||||
add_to_args = []
|
||||
if '--debug' not in args_with_config_defaults:
|
||||
if '--traceback' not in args_with_config_defaults:
|
||||
add_to_args.append('--traceback')
|
||||
if not any('--timeout' in arg for arg in args_with_config_defaults):
|
||||
add_to_args.append('--timeout=3')
|
||||
args = add_to_args + args
|
||||
|
||||
def dump_stderr():
|
||||
stderr.seek(0)
|
||||
|
Loading…
Reference in New Issue
Block a user