From 3eb9cc0da818d5f35d78378e245c86b2a0558367 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 31 May 2024 15:21:04 +0200 Subject: [PATCH 1/3] MSC4108: Add a Content-Type header on the PUT response This is a workaround for some proxy setup, where the ETag header gets stripped from the response headers unless there is a Content-Type header set. --- rust/src/rendezvous/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rust/src/rendezvous/mod.rs b/rust/src/rendezvous/mod.rs index f69f45490f0..0f1e97efbd3 100644 --- a/rust/src/rendezvous/mod.rs +++ b/rust/src/rendezvous/mod.rs @@ -288,6 +288,12 @@ impl RendezvousHandler { let mut response = Response::new(Bytes::new()); *response.status_mut() = StatusCode::ACCEPTED; prepare_headers(response.headers_mut(), session); + + // Even though this isn't mandated by the MSC, we set a Content-Type on the response. It + // doesn't do any harm as the body is empty, but this helps escape a bug in some reverse + // proxy/cache setup which strips the ETag header if there is no Content-Type set. + response.headers_mut().typed_insert(ContentType::text()); + http_response_to_twisted(twisted_request, response)?; Ok(()) From e8ce1ecbfe9aa8da6ab8e04860542459361dd4fa Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:35:16 +0100 Subject: [PATCH 2/3] Mention Cloudflare in the comment --- rust/src/rendezvous/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/src/rendezvous/mod.rs b/rust/src/rendezvous/mod.rs index 0f1e97efbd3..55df0203f3f 100644 --- a/rust/src/rendezvous/mod.rs +++ b/rust/src/rendezvous/mod.rs @@ -292,6 +292,7 @@ impl RendezvousHandler { // Even though this isn't mandated by the MSC, we set a Content-Type on the response. It // doesn't do any harm as the body is empty, but this helps escape a bug in some reverse // proxy/cache setup which strips the ETag header if there is no Content-Type set. + // Specifically, we noticed this behaviour when placing Synapse behind Cloudflare. response.headers_mut().typed_insert(ContentType::text()); http_response_to_twisted(twisted_request, response)?; From 3b199d0aa0d6993187a5a66a27438bc29ee8e905 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Tue, 26 Nov 2024 16:34:53 +0100 Subject: [PATCH 3/3] Newsfile --- changelog.d/17253.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17253.misc diff --git a/changelog.d/17253.misc b/changelog.d/17253.misc new file mode 100644 index 00000000000..868691624d0 --- /dev/null +++ b/changelog.d/17253.misc @@ -0,0 +1 @@ +[MSC4108](https://github.com/matrix-org/matrix-spec-proposals/pull/4108): Add a `Content-Type` header on the `PUT` response to work around a faulty behavior in some caching reverse proxies.