This release adds experimental OpenTelemetry tracing, HTTP QUERY support, and response trailers in TestClient. Starlette now requires AnyIO 4.
Warning
OpenTelemetryMiddleware is experimental. Its API and emitted telemetry may change in minor releases without a deprecation period.
Added
- Add experimental
OpenTelemetryMiddlewarefor HTTP server spans, with URL exclusions and custom tracer providers #3438, #3463, and #3520. - Expose the matched route through
scope["route"]#3438. - Support the
QUERYHTTP method inHTTPEndpoint, CORS, and OpenAPI 3.2 schema generation #3489. - Capture HTTP response trailers in
TestClientand expose them throughresponse.extensions["http.response.trailers"]#3563. - Support partitioned cookies in
SessionMiddleware#3510. - Add
partitionedtoResponse.delete_cookie()on Python 3.14 and later #3376. - Support IPv6 hosts in
TrustedHostMiddlewareandTestClient#3471. - Support Python 3.15 #3508.
Changed
- Require
anyio>=4.0.0,<5, dropping support for AnyIO 3 #3512. - Raise
WebSocketDisconnected, aRuntimeErrorsubclass, for disconnected WebSocket operations #2767. - Accept
Collection[str]inCORSMiddlewareconfiguration annotations, including sets and frozensets #3518.
Fixed
- Run background tasks only after the response is sent when using
BaseHTTPMiddleware#3476. - Return
400for invalid multipart parser input #3492. - Include
Vary: Originon all normal CORS responses and vary preflight responses by all request headers that affect them #3516 and #3517. - Handle malformed
Hostheaders and IPv6 authorities consistently across URL construction, host routing, and redirect middleware #3472. - Ignore
Rangeheaders whenFileResponsehas a status other than200, preserving its status and full body #3568. - Handle standalone
If-None-Match: *inStaticFiles#3201. - Reject WebSocket requests to
StaticFileswithout raising an assertion error #3532. - Persist session mutations made with
popitem()and|=#3436. - Handle empty and absent payloads in
WebSocketEndpoint.decode()#3372. - Implement
identityonSimpleUserandUnauthenticatedUser#3271. - Allow
HTTPExceptionto use non-standard status codes without an explicitdetail#3545. - Avoid deprecated AnyIO imports in
TestClientand add explicit imports inWSGIMiddlewarefor AnyIO 4.15 compatibility #3498 and #3501. - Offload debug traceback rendering to a worker thread in
ServerErrorMiddleware#2858.
Full changelog: 1.6.0...1.7.0