mirror of
https://github.com/httpie/cli.git
synced 2025-01-13 17:18:32 +01:00
Documented config.
Also renamed `default_content_type` to `implicit_content_type` .
This commit is contained in:
parent
548bef7dff
commit
4a6f32a0f4
114
README.rst
114
README.rst
@ -258,7 +258,7 @@ JSON
|
||||
====
|
||||
|
||||
JSON is the *lingua franca* of modern web services and it is also the
|
||||
**default content type** HTTPie uses:
|
||||
**implicit content type** HTTPie by default uses:
|
||||
|
||||
If your command includes some data items, they are serialized as a JSON
|
||||
object by default. HTTPie also automatically sets the following headers,
|
||||
@ -269,9 +269,9 @@ both of which can be overwritten:
|
||||
``Accept`` ``application/json``
|
||||
================ =======================================
|
||||
|
||||
You can use ``--json`` / ``-j`` to set ``Accept`` to ``application/json``
|
||||
regardless of whether you are sending data (it's a shortcut for setting
|
||||
the header via the usual header notation –
|
||||
You can use ``--json`` / ``-j`` to explicitly set ``Accept``
|
||||
to ``application/json`` regardless of whether you are sending data
|
||||
(it's a shortcut for setting the header via the usual header notation –
|
||||
``http url Accept:application/json``).
|
||||
|
||||
Simple example:
|
||||
@ -338,6 +338,9 @@ difference is in adding the ``--form`` / ``-f`` option, which ensures that
|
||||
data fields are serialized as, and ``Content-Type`` is set to,
|
||||
``application/x-www-form-urlencoded; charset=utf-8``.
|
||||
|
||||
It is possible to make form data the implicit content type via the `config`_
|
||||
file.
|
||||
|
||||
|
||||
-------------
|
||||
Regular Forms
|
||||
@ -502,43 +505,6 @@ path. The path can also be configured via the environment variable
|
||||
``REQUESTS_CA_BUNDLE``.
|
||||
|
||||
|
||||
========
|
||||
Sessions
|
||||
========
|
||||
|
||||
*NOTE: This is an experimental feature. Feedback appretiated.*
|
||||
|
||||
HTTPie supports named, per-host sessions, where custom headers, authorization,
|
||||
and cookies (manually specified or sent by the server) persist between requests:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --session user1 -a user1:password example.org X-Foo:Bar
|
||||
|
||||
Now you can refer to the session by its name:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --session user1 example.org
|
||||
|
||||
|
||||
To switch to another session simple pass a different name:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --session user2 -a user2:password example.org X-Bar:Foo
|
||||
|
||||
To use a session without updating it from the request/response exchange
|
||||
once it is created, specify the session name via
|
||||
``--session-read-only=SESSION_NAME`` instead.
|
||||
|
||||
You can view and manipulate existing sessions via the ``httpie`` management
|
||||
command, see ``httpie --help``.
|
||||
|
||||
Sessions are stored as JSON in ``~/.httpie/sessions/<host>/<name>.json``
|
||||
(``%APPDATA%\httpie\sessions\<host>\<name>.json`` on Windows).
|
||||
|
||||
|
||||
==============
|
||||
Output Options
|
||||
==============
|
||||
@ -854,6 +820,71 @@ Streamed output by small chunks alá ``tail -f``:
|
||||
| while read tweet; do echo "$tweet" | http POST example.org/tweets ; done
|
||||
|
||||
|
||||
|
||||
========
|
||||
Sessions
|
||||
========
|
||||
|
||||
HTTPie supports named, per-host sessions, where custom headers, authorization,
|
||||
and cookies (manually specified or sent by the server) persist between requests:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --session user1 -a user1:password example.org X-Foo:Bar
|
||||
|
||||
Now you can refer to the session by its name:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --session user1 example.org
|
||||
|
||||
|
||||
To switch to another session simple pass a different name:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ http --session user2 -a user2:password example.org X-Bar:Foo
|
||||
|
||||
To use a session without updating it from the request/response exchange
|
||||
once it is created, specify the session name via
|
||||
``--session-read-only=SESSION_NAME`` instead.
|
||||
|
||||
You can view and manipulate existing sessions via the ``httpie`` management
|
||||
command, see ``httpie --help``.
|
||||
|
||||
Sessions are stored as JSON in ``~/.httpie/sessions/<host>/<name>.json``
|
||||
(``%APPDATA%\httpie\sessions\<host>\<name>.json`` on Windows).
|
||||
|
||||
See also `config`_.
|
||||
|
||||
|
||||
======
|
||||
Config
|
||||
======
|
||||
|
||||
HTTPie provides a simple configuration file containing a JSON
|
||||
object with the following keys:
|
||||
|
||||
========================= =================================================
|
||||
``__version__`` HTTPie automatically sets this to its version.
|
||||
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``.
|
||||
|
||||
``default_options`` An ``Array`` (by default empty) of options
|
||||
that should be applied to every request.
|
||||
========================= =================================================
|
||||
|
||||
The default location is ``~/.httpie/config.json``
|
||||
(``%APPDATA%\httpie\config.json`` on Windows).
|
||||
|
||||
The config directory location can be changed by setting the
|
||||
``HTTPIE_CONFIG_DIR`` environment variable.
|
||||
|
||||
|
||||
=========
|
||||
Scripting
|
||||
=========
|
||||
@ -995,6 +1026,7 @@ Changelog
|
||||
*You can click a version name to see a diff with the previous one.*
|
||||
|
||||
* `0.2.8-alpha`_
|
||||
* Added config file.
|
||||
* Added persistent session support.
|
||||
* Renamed ``--allow-redirects`` to ``--follow``.
|
||||
* Improved the usability of ``http --help``.
|
||||
|
@ -74,7 +74,7 @@ class Config(BaseConfigDict):
|
||||
name = 'config'
|
||||
|
||||
DEFAULTS = {
|
||||
'default_content_type': 'json',
|
||||
'implicit_content_type': 'json',
|
||||
'default_options': []
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ from .cli import parser
|
||||
from .client import get_response
|
||||
from .models import Environment
|
||||
from .output import output_stream, write, write_with_colors_win_p3k
|
||||
from .config import DEFAULT_CONFIG_DIR, Config
|
||||
from . import EXIT
|
||||
|
||||
|
||||
|
@ -102,7 +102,7 @@ class Parser(ArgumentParser):
|
||||
|
||||
args = super(Parser, self).parse_args(args, namespace)
|
||||
|
||||
if not args.json and env.config.default_content_type == 'form':
|
||||
if not args.json and env.config.implicit_content_type == 'form':
|
||||
args.form = True
|
||||
|
||||
if args.debug:
|
||||
|
@ -109,6 +109,7 @@ class TestEnvironment(Environment):
|
||||
stdin_isatty = True,
|
||||
stdout_isatty = True
|
||||
is_windows = False
|
||||
_shutil = shutil # we need it in __del__ (would get gc'd)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
@ -127,7 +128,7 @@ class TestEnvironment(Environment):
|
||||
|
||||
def __del__(self):
|
||||
if self.delete_config_dir:
|
||||
shutil.rmtree(self.config_dir)
|
||||
self._shutil.rmtree(self.config_dir)
|
||||
|
||||
def has_docutils():
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user