Landed
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
3 files changed+33 added−0 removed
modified:axum/src/routing/tests/mod.rs+28 added
1298 unmodified lines1299 let body = res.collect().await.unwrap().to_bytes();1300 assert!(body.is_empty());1301 }1302 1303+// https://httpwg.org/specs/rfc9110.html#CONNECT1304 #[crate::test]1305+async 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+ });1315+1316+ 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();1322+1323+ 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+}1330+1331+#[crate::test]1332 async fn impl_handler_for_into_response() {1333 let app = Router::new().route("/things", post((StatusCode::CREATED, "thing created")));1334 1335 let client = TestClient::new(app);55 unmodified linesmodified:axum/src/routing/route.rs+2 added
157 unmodified lines158 || 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 linesmodified:axum/CHANGELOG.md+3 added
39 unmodified lines40 - **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])46 47 [#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/320513 unmodified lines63 [#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/390768 69 # 0.8.970 71 - **added:** `WebSocketUpgrade::{requested_protocols, set_selected_protocol}` for more2409 unmodified lines