Skip to content

Commit cee9da0

Browse files
MSC4108: Add a Content-Type header on the PUT response (#17253)
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. In particular, we saw this bug when putting Cloudflare in front of Synapse. I'm pretty sure this is a Cloudflare bug, as this behaviour isn't documented anywhere, and doesn't make sense whatsoever. --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
1 parent a9c4d1c commit cee9da0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

changelog.d/17253.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

rust/src/rendezvous/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ impl RendezvousHandler {
288288
let mut response = Response::new(Bytes::new());
289289
*response.status_mut() = StatusCode::ACCEPTED;
290290
prepare_headers(response.headers_mut(), session);
291+
292+
// Even though this isn't mandated by the MSC, we set a Content-Type on the response. It
293+
// doesn't do any harm as the body is empty, but this helps escape a bug in some reverse
294+
// proxy/cache setup which strips the ETag header if there is no Content-Type set.
295+
// Specifically, we noticed this behaviour when placing Synapse behind Cloudflare.
296+
response.headers_mut().typed_insert(ContentType::text());
297+
291298
http_response_to_twisted(twisted_request, response)?;
292299

293300
Ok(())

0 commit comments

Comments
 (0)