diff --git a/.gitignore b/.gitignore index c5856256..3bdb64f3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ README.html htmlcov .idea .DS_Store +.cache/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 856364d4..006a35c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,7 +8,8 @@ This project adheres to `Semantic Versioning `_. `1.0.0-dev`_ (Unreleased) ------------------------- -* Changed the default color style back to ``solarized`` as it supports +* Added ``Content-Type`` of files uploaded in ``multipart/form-data`` requests. +* Changed the default color style back to``solarized`` as it supports both the light and dark terminal background mode. diff --git a/httpie/input.py b/httpie/input.py index b0fbd772..6e259bbe 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -605,9 +605,13 @@ class DataDict(RequestItemsDict): RequestItems = namedtuple('RequestItems', ['headers', 'data', 'files', 'params']) + def get_content_type(filename): - """Get content type for a filename in format appropriate for Content-Type - headers. + """ + Return the content type for ``filename`` in format appropriate + for Content-Type headers, or ``None`` if the file type is unknown + to ``mimetypes``. + """ mime, encoding = mimetypes.guess_type(filename, strict=False) if mime: @@ -616,6 +620,7 @@ def get_content_type(filename): content_type = '%s; charset=%s' % (mime, encoding) return content_type + def parse_items(items, headers_class=CaseInsensitiveDict, data_class=OrderedDict, diff --git a/tests/test_uploads.py b/tests/test_uploads.py index 0bf8457e..5cbe2cab 100644 --- a/tests/test_uploads.py +++ b/tests/test_uploads.py @@ -23,6 +23,7 @@ class TestMultipartFormDataFileUpload: ' filename="%s"' % os.path.basename(FILE_PATH) in r assert FILE_CONTENT in r assert '"foo": "bar"' in r + assert 'Content-Type: text/plain' in r def test_upload_multiple_fields_with_the_same_name(self, httpbin): r = http('--form', '--verbose', 'POST', httpbin.url + '/post', @@ -34,6 +35,7 @@ class TestMultipartFormDataFileUpload: # Should be 4, but is 3 because httpbin # doesn't seem to support filed field lists assert r.count(FILE_CONTENT) in [3, 4] + assert r.count('Content-Type: text/plain') == 2 class TestRequestBodyFromFilePath: