From 4a6f32a0f44fdc32bd1de9a12b8495bd5368828b Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Mon, 17 Sep 2012 02:39:23 +0200 Subject: [PATCH] Documented config. Also renamed `default_content_type` to `implicit_content_type` . --- README.rst | 114 ++++++++++++++++++++++++++++++----------------- httpie/config.py | 2 +- httpie/core.py | 1 - httpie/input.py | 2 +- tests/tests.py | 3 +- 5 files changed, 77 insertions(+), 45 deletions(-) diff --git a/README.rst b/README.rst index 08887ba8..d4fb3f98 100644 --- a/README.rst +++ b/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//.json`` -(``%APPDATA%\httpie\sessions\\.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//.json`` +(``%APPDATA%\httpie\sessions\\.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``. diff --git a/httpie/config.py b/httpie/config.py index e35fd75a..5fbd2610 100644 --- a/httpie/config.py +++ b/httpie/config.py @@ -74,7 +74,7 @@ class Config(BaseConfigDict): name = 'config' DEFAULTS = { - 'default_content_type': 'json', + 'implicit_content_type': 'json', 'default_options': [] } diff --git a/httpie/core.py b/httpie/core.py index ba46163c..fa93ef88 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -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 diff --git a/httpie/input.py b/httpie/input.py index 1b8ad1df..3300a42c 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -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: diff --git a/tests/tests.py b/tests/tests.py index 3a23a2e4..02e8b52b 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -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: