Skip to content
Myr

axum: Remove framing headers from successful CONNECT responses (#3907)

Landed as e57b547

authored by Jayakumar Thanakodi · committed by the platform · parent dcfd5e3 · Browse files · 3 files+33 added−0 removed
This landing

State

Landed as e57b547

By oscabriel

Diff stats

3 files+33 added−0 removed

  • tests:+28 added−0 removed
  • other:+5 added−0 removed

3 files+33 added−0 removed

modified:axum/src/routing/tests/mod.rs+28 added
1298 unmodified lines
1299 let body = res.collect().await.unwrap().to_bytes();1300 assert!(body.is_empty());1301}13021303// https://httpwg.org/specs/rfc9110.html#CONNECT1304#[crate::test]1305async fn successful_connect_drops_body_and_framing_headers() {1306 let app = Router::new().fallback(|| async {1307 (1308 [1309 (CONTENT_LENGTH, "5"),1310 (http::header::TRANSFER_ENCODING, "chunked"),1311 ],1312 "hello",1313 )1314 });13151316 let req = Request::builder()1317 .uri("example.com:443")1318 .method(Method::CONNECT)1319 .header(HOST, "example.com:443")1320 .body(Body::empty())1321 .unwrap();13221323 let res = app.oneshot(req).await.unwrap();1324 assert_eq!(res.status(), StatusCode::OK);1325 assert!(res.headers().get(CONTENT_LENGTH).is_none());1326 assert!(res.headers().get(http::header::TRANSFER_ENCODING).is_none());1327 let body = res.collect().await.unwrap().to_bytes();1328 assert!(body.is_empty());1329}13301331#[crate::test]1332async fn impl_handler_for_into_response() {1333 let app = Router::new().route("/things", post((StatusCode::CREATED, "thing created")));13341335 let client = TestClient::new(app);
55 unmodified lines
modified:axum/src/routing/route.rs+2 added
157 unmodified lines
158 || res.size_hint().lower() != 0159 {160 error!("response to CONNECT with nonempty body");161 res = res.map(|_| Body::empty());162 res.headers_mut().remove(&CONTENT_LENGTH);163 res.headers_mut().remove(&header::TRANSFER_ENCODING);164 }165 } else if *this.top_level {166 if res.status() == http::StatusCode::METHOD_NOT_ALLOWED {167 // From https://httpwg.org/specs/rfc9110.html#field.allow:
143 unmodified lines
modified:axum/CHANGELOG.md+3 added
39 unmodified lines
40- **changed:** `Router::merge` no longer wraps service routes in another `Route`,41 which saves a clone and a layer of boxing on every request to them ([#3909])42- **changed:** Update `Router::route_service` docs for `axum::body::Body` instead of43 the removed `BoxBody` type ([#3890])44- **fixed:** Successful responses to `CONNECT` no longer keep `content-length` or45 `transfer-encoding` headers after their body is removed ([#3907])4647[#3158]: https://github.com/tokio-rs/axum/pull/315848[#3261]: https://github.com/tokio-rs/axum/pull/326149[#3205]: https://github.com/tokio-rs/axum/pull/3205
13 unmodified lines
63[#3867]: https://github.com/tokio-rs/axum/pull/386764[#3890]: https://github.com/tokio-rs/axum/pull/389065[#3779]: https://github.com/tokio-rs/axum/pull/377966[#3928]: https://github.com/tokio-rs/axum/pull/392867[#3907]: https://github.com/tokio-rs/axum/pull/39076869# 0.8.97071- **added:** `WebSocketUpgrade::{requested_protocols, set_selected_protocol}` for more
2409 unmodified lines