Use latin-1 for WSGI environ path and headers

PA
5h ago
+22-3

Summary

PEP 3333 wants environ strings to hold the raw bytes decoded as latin-1. WSGITransport passed the decoded unicode path as PATH_INFO, and used ascii for header values. With a Flask/werkzeug app:

  • GET /caf%C3%A9 -> the app sees /caf�
  • GET /euro/%E2%82%AC -> UnicodeEncodeError inside werkzeug
  • a non-ASCII request or response header value -> UnicodeDecodeError / UnicodeEncodeError

PATH_INFO is now built from the raw path bytes (unquote_to_bytes on raw_path) and decoded as latin-1, and header values use latin-1 both ways. encode/httpx#1391 fixed the unquoting for this, but not the encoding, so the example in encode/httpx#1365 still failed.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.