Fixed --output=/dev/null on Linux

Closes #252
This commit is contained in:
Jakub Roztocil 2014-09-07 10:20:32 +02:00
parent af873effb6
commit b0effe07d9
3 changed files with 21 additions and 1 deletions

View File

@ -1280,6 +1280,7 @@ Changelog
* To make it easier to deal with Windows paths in request items, ``\`` * To make it easier to deal with Windows paths in request items, ``\``
now only escapes special characters (the ones that are used as key-value now only escapes special characters (the ones that are used as key-value
separators). separators).
* Fixed ``--output=/dev/null`` on Linux.
* `0.8.0`_ (2014-01-25) * `0.8.0`_ (2014-01-25)
* Added ``field=@file.txt`` and ``field:=@file.json`` for embedding * Added ``field=@file.txt`` and ``field:=@file.json`` for embedding
the contents of text and JSON files into request data. the contents of text and JSON files into request data.

View File

@ -5,6 +5,7 @@ import os
import sys import sys
import re import re
import json import json
import errno
import mimetypes import mimetypes
import getpass import getpass
from io import BytesIO from io import BytesIO
@ -185,7 +186,14 @@ class Parser(ArgumentParser):
# `stdout`. The file is opened for appending, which isn't what # `stdout`. The file is opened for appending, which isn't what
# we want in this case. # we want in this case.
self.args.output_file.seek(0) self.args.output_file.seek(0)
try:
self.args.output_file.truncate() self.args.output_file.truncate()
except IOError as e:
if e.errno == errno.EINVAL:
# E.g. /dev/null on Linux.
pass
else:
raise
self.env.stdout = self.args.output_file self.env.stdout = self.args.output_file
self.env.stdout_isatty = False self.env.stdout_isatty = False

View File

@ -1,6 +1,8 @@
"""Miscellaneous regression tests""" """Miscellaneous regression tests"""
import pytest
from utils import http, HTTP_OK from utils import http, HTTP_OK
from httpie.compat import is_windows
def test_Host_header_overwrite(httpbin): def test_Host_header_overwrite(httpbin):
@ -14,3 +16,12 @@ def test_Host_header_overwrite(httpbin):
assert HTTP_OK in r assert HTTP_OK in r
assert r.lower().count('host:') == 1 assert r.lower().count('host:') == 1
assert 'host: {0}'.format(host) in r assert 'host: {0}'.format(host) in r
@pytest.mark.skipif(is_windows, reason='Unix-only')
def test_output_devnull(httpbin):
"""
https://github.com/jakubroztocil/httpie/issues/252
"""
http('--output=/dev/null', httpbin + '/get')