forked from extern/httpie-cli
parent
41e822ca2f
commit
49a0fb6e0f
@ -15,6 +15,8 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
|
|||||||
* Added the ability to unset a request header with ``Header:``, and send an
|
* Added the ability to unset a request header with ``Header:``, and send an
|
||||||
empty value with ``Header;``.
|
empty value with ``Header;``.
|
||||||
* Added ``--default-scheme <URL_SCHEME>``.
|
* Added ``--default-scheme <URL_SCHEME>``.
|
||||||
|
* Changed the default JSON ``Accept`` header from ``application/json``
|
||||||
|
to ``application/json, */*``.
|
||||||
|
|
||||||
|
|
||||||
`0.9.4`_ (2016-07-01)
|
`0.9.4`_ (2016-07-01)
|
||||||
|
12
README.rst
12
README.rst
@ -183,7 +183,7 @@ with `authentication`_:
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ http -a USERNAME POST https://api.github.com/repos/jkbrzt/httpie/issues/83/comments body='HTTPie is awesome!'
|
$ http -a USERNAME POST https://api.github.com/repos/jkbrzt/httpie/issues/83/comments body='HTTPie is awesome! :heart:'
|
||||||
|
|
||||||
|
|
||||||
Upload a file using `redirected input`_:
|
Upload a file using `redirected input`_:
|
||||||
@ -403,13 +403,13 @@ both of which can be overwritten:
|
|||||||
|
|
||||||
================ =======================================
|
================ =======================================
|
||||||
``Content-Type`` ``application/json``
|
``Content-Type`` ``application/json``
|
||||||
``Accept`` ``application/json``
|
``Accept`` ``application/json, */*``
|
||||||
================ =======================================
|
================ =======================================
|
||||||
|
|
||||||
You can use ``--json, -j`` to explicitly set ``Accept``
|
You can use ``--json, -j`` to explicitly set ``Accept``
|
||||||
to ``application/json`` regardless of whether you are sending data
|
to ``application/json`` regardless of whether you are sending data
|
||||||
(it's a shortcut for setting the header via the usual header notation –
|
(it's a shortcut for setting the header via the usual header notation –
|
||||||
``http url Accept:application/json``). Additionally,
|
``http url Accept:application/json, */*``). Additionally,
|
||||||
HTTPie will try to detect JSON responses even when the
|
HTTPie will try to detect JSON responses even when the
|
||||||
``Content-Type`` is incorrectly ``text/plain`` or unknown.
|
``Content-Type`` is incorrectly ``text/plain`` or unknown.
|
||||||
|
|
||||||
@ -422,7 +422,7 @@ Simple example:
|
|||||||
.. code-block:: http
|
.. code-block:: http
|
||||||
|
|
||||||
PUT / HTTP/1.1
|
PUT / HTTP/1.1
|
||||||
Accept: application/json
|
Accept: application/json, */*
|
||||||
Accept-Encoding: gzip, deflate
|
Accept-Encoding: gzip, deflate
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Host: example.org
|
Host: example.org
|
||||||
@ -449,7 +449,7 @@ fields using ``=@`` and ``:=@``:
|
|||||||
.. code-block:: http
|
.. code-block:: http
|
||||||
|
|
||||||
PUT /person/1 HTTP/1.1
|
PUT /person/1 HTTP/1.1
|
||||||
Accept: application/json
|
Accept: application/json, */*
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Host: api.example.com
|
Host: api.example.com
|
||||||
|
|
||||||
@ -825,7 +825,7 @@ documentation examples:
|
|||||||
|
|
||||||
$ http --verbose PUT httpbin.org/put hello=world
|
$ http --verbose PUT httpbin.org/put hello=world
|
||||||
PUT /put HTTP/1.1
|
PUT /put HTTP/1.1
|
||||||
Accept: application/json
|
Accept: application/json, */*
|
||||||
Accept-Encoding: gzip, deflate
|
Accept-Encoding: gzip, deflate
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Host: httpbin.org
|
Host: httpbin.org
|
||||||
|
@ -24,8 +24,9 @@ except AttributeError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
FORM = 'application/x-www-form-urlencoded; charset=utf-8'
|
FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=utf-8'
|
||||||
JSON = 'application/json'
|
JSON_CONTENT_TYPE = 'application/json'
|
||||||
|
JSON_ACCEPT = '{0}, */*'.format(JSON_CONTENT_TYPE)
|
||||||
DEFAULT_UA = 'HTTPie/%s' % __version__
|
DEFAULT_UA = 'HTTPie/%s' % __version__
|
||||||
|
|
||||||
|
|
||||||
@ -100,16 +101,15 @@ def get_default_headers(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto_json = args.data and not args.form
|
auto_json = args.data and not args.form
|
||||||
# FIXME: Accept is set to JSON with `http url @./file.txt`.
|
|
||||||
if args.json or auto_json:
|
if args.json or auto_json:
|
||||||
default_headers['Accept'] = 'application/json'
|
default_headers['Accept'] = JSON_ACCEPT
|
||||||
if args.json or (auto_json and args.data):
|
if args.json or (auto_json and args.data):
|
||||||
default_headers['Content-Type'] = JSON
|
default_headers['Content-Type'] = JSON_CONTENT_TYPE
|
||||||
|
|
||||||
elif args.form and not args.files:
|
elif args.form and not args.files:
|
||||||
# If sending files, `requests` will set
|
# If sending files, `requests` will set
|
||||||
# the `Content-Type` for us.
|
# the `Content-Type` for us.
|
||||||
default_headers['Content-Type'] = FORM
|
default_headers['Content-Type'] = FORM_CONTENT_TYPE
|
||||||
return default_headers
|
return default_headers
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
Tests for the provided defaults regarding HTTP method, and --json vs. --form.
|
Tests for the provided defaults regarding HTTP method, and --json vs. --form.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from httpie.client import JSON_ACCEPT
|
||||||
from utils import TestEnvironment, http, HTTP_OK
|
from utils import TestEnvironment, http, HTTP_OK
|
||||||
from fixtures import FILE_PATH
|
from fixtures import FILE_PATH
|
||||||
|
|
||||||
@ -58,20 +59,20 @@ class TestAutoContentTypeAndAcceptHeaders:
|
|||||||
def test_POST_with_data_auto_JSON_headers(self, httpbin):
|
def test_POST_with_data_auto_JSON_headers(self, httpbin):
|
||||||
r = http('POST', httpbin.url + '/post', 'a=b')
|
r = http('POST', httpbin.url + '/post', 'a=b')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert '"Accept": "application/json"' in r
|
assert r.json['headers']['Accept'] == JSON_ACCEPT
|
||||||
assert '"Content-Type": "application/json' in r
|
assert r.json['headers']['Content-Type'] == 'application/json'
|
||||||
|
|
||||||
def test_GET_with_data_auto_JSON_headers(self, httpbin):
|
def test_GET_with_data_auto_JSON_headers(self, httpbin):
|
||||||
# JSON headers should automatically be set also for GET with data.
|
# JSON headers should automatically be set also for GET with data.
|
||||||
r = http('POST', httpbin.url + '/post', 'a=b')
|
r = http('POST', httpbin.url + '/post', 'a=b')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert '"Accept": "application/json"' in r, r
|
assert r.json['headers']['Accept'] == JSON_ACCEPT
|
||||||
assert '"Content-Type": "application/json' in r
|
assert r.json['headers']['Content-Type'] == 'application/json'
|
||||||
|
|
||||||
def test_POST_explicit_JSON_auto_JSON_accept(self, httpbin):
|
def test_POST_explicit_JSON_auto_JSON_accept(self, httpbin):
|
||||||
r = http('--json', 'POST', httpbin.url + '/post')
|
r = http('--json', 'POST', httpbin.url + '/post')
|
||||||
assert HTTP_OK in r
|
assert HTTP_OK in r
|
||||||
assert r.json['headers']['Accept'] == 'application/json'
|
assert r.json['headers']['Accept'] == JSON_ACCEPT
|
||||||
# Make sure Content-Type gets set even with no data.
|
# Make sure Content-Type gets set even with no data.
|
||||||
# https://github.com/jkbrzt/httpie/issues/137
|
# https://github.com/jkbrzt/httpie/issues/137
|
||||||
assert 'application/json' in r.json['headers']['Content-Type']
|
assert 'application/json' in r.json['headers']['Content-Type']
|
||||||
|
Loading…
Reference in New Issue
Block a user