Skip to content
Myr

BUG: wsgi.error should be TextIO, not BytesIO in WSGI transport (#1828)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* wsgi.error should be StringIO, not BytesIO Based on the documentation at https://modwsgi.readthedocs.io/en/master/user-guides/debugging-techniques.html#apache-error-log-files * Default to sys.stderr and add test * rename log_file param to wsgi_errors

authored by Adrian Garcia Badaracco · committed by GitHub · parent c24bbb8 · Browse files · 2 files+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

2 files+21 added−1 removed

  • tests:+17 added−0 removed
  • other:+4 added−1 removed

2 files+21 added−1 removed

modified:httpx/_transports/wsgi.py+4 added-1 removed
1import io2import itertools3import sys4import typing5from urllib.parse import unquote67from .base import BaseTransport, SyncByteStream
59 unmodified lines
67 app: typing.Callable,68 raise_app_exceptions: bool = True,69 script_name: str = "",70 remote_addr: str = "127.0.0.1",71 wsgi_errors: typing.Optional[typing.TextIO] = None,72 ) -> None:73 self.app = app74 self.raise_app_exceptions = raise_app_exceptions75 self.script_name = script_name76 self.remote_addr = remote_addr77 self.wsgi_errors = wsgi_errors7879 def handle_request(80 self,81 method: bytes,
14 unmodified lines
96 environ = {97 "wsgi.version": (1, 0),98 "wsgi.url_scheme": scheme.decode("ascii"),99 "wsgi.input": wsgi_input,97 "wsgi.errors": io.BytesIO(),100 "wsgi.errors": self.wsgi_errors or sys.stderr,101 "wsgi.multithread": True,102 "wsgi.multiprocess": False,103 "wsgi.run_once": False,104 "REQUEST_METHOD": method.decode(),
42 unmodified lines
modified:tests/test_wsgi.py+17 added
1import sys2import wsgiref.validate3from functools import partial4from io import StringIO56import pytest78import httpx
61 unmodified lines
7071 return [output]727374def log_to_wsgi_log_buffer(environ, start_response):75 print("test1", file=environ["wsgi.errors"])76 environ["wsgi.errors"].write("test2")77 return echo_body(environ, start_response)787980def test_wsgi():81 client = httpx.Client(app=application_factory([b"Hello, World!"]))82 response = client.get("http://www.example.org/")83 assert response.status_code == 200
41 unmodified lines
125 assert response.status_code == 200126 assert response.text == ""127128129def test_logging():130 buffer = StringIO()131 transport = httpx.WSGITransport(app=log_to_wsgi_log_buffer, wsgi_errors=buffer)132 client = httpx.Client(transport=transport)133 response = client.post("http://www.example.org/", content=b"example")134 assert response.status_code == 200 # no errors135 buffer.seek(0)136 assert buffer.read() == "test1\ntest2"137138139@pytest.mark.parametrize(140 "url, expected_server_port",141 [142 pytest.param("http://www.example.org", "80", id="auto-http"),
21 unmodified lines