miscellaneous regression tests import pytest from httpie compat import iswindows from utils matching import assertoutputmatches expect from utils import httpok mockenvironment http def testhostheaderoverwritehttpbin host pie dev url httpbin url get r http printhh url f host host assert httpok in r assert r lower count host 1 assert f host host in r pytest mark skipifiswindows reason unixonly def testoutputdevnullhttpbin http outputdevnull httpbin get def testverboseredirectedstdoutseparatorhttpbin r http v httpbin url post ab envmockenvironmentstdoutisattyfalse assert http not in r assertoutputmatchesr expect requestheaders expect body expect separator expect responseheaders expect body https github com httpie cli issues 235 https github com httpie cli issues 252 https github com httpie cli issues 1006
import pytest

from httpie.compat import is_windows
from .utils.matching import assert_output_matches, Expect
from .utils import HTTP_OK, MockEnvironment, http


def test_Host_header_overwrite(httpbin):
    
    host = 'pie.dev'
    url = httpbin.url + '/get'
    r = http('--print=hH', url, f'host:{host}')
    assert HTTP_OK in r
    assert r.lower().count('host:') == 1
    assert f'host: {host}' in r


@pytest.mark.skipif(is_windows, reason='Unix-only')
def test_output_devnull(httpbin):
    
    http('--output=/dev/null', httpbin + '/get')


def test_verbose_redirected_stdout_separator(httpbin):
    
    r = http(
        '-v',
        httpbin.url + '/post',
        'a=b',
        env=MockEnvironment(stdout_isatty=False),
    )
    assert '}HTTP/' not in r
    assert_output_matches(r, [
        Expect.REQUEST_HEADERS,
        Expect.BODY,
        Expect.SEPARATOR,
        Expect.RESPONSE_HEADERS,
        Expect.BODY,
    ])