Skip to content

Commit

Permalink
Documented config.
Browse files Browse the repository at this point in the history
Also renamed `default_content_type` to `implicit_content_type` .
  • Loading branch information
jkbrzt committed Sep 17, 2012
1 parent 548bef7 commit 4a6f32a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 45 deletions.
114 changes: 73 additions & 41 deletions README.rst
Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
==============
Expand Down Expand Up @@ -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
=========
Expand Down Expand Up @@ -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``.
Expand Down
2 changes: 1 addition & 1 deletion httpie/config.py
Expand Up @@ -74,7 +74,7 @@ class Config(BaseConfigDict):
name = 'config'

DEFAULTS = {
'default_content_type': 'json',
'implicit_content_type': 'json',
'default_options': []
}

Expand Down
1 change: 0 additions & 1 deletion httpie/core.py
Expand Up @@ -23,7 +23,6 @@
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


Expand Down
2 changes: 1 addition & 1 deletion httpie/input.py
Expand Up @@ -102,7 +102,7 @@ def parse_args(self, env, args=None, namespace=None):

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:
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.py
Expand Up @@ -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):

Expand All @@ -127,7 +128,7 @@ def __init__(self, **kwargs):

def __del__(self):
if self.delete_config_dir:
shutil.rmtree(self.config_dir)
self._shutil.rmtree(self.config_dir)

def has_docutils():
try:
Expand Down

0 comments on commit 4a6f32a

Please sign in to comment.