Manually set ContentType for Response #2735
Replies: 3 comments
-
I went ahead and implemented my hack in For now,
|
Beta Was this translation helpful? Give feedback.
-
Consider implementing your own JSON-like responder that sets the proper content-type. Doing so is rather easy: #[derive(Responder)]
#[response(content_type = "application/activity+json")]
struct ActivityJson<T>(Json<T>); Then just respond with an |
Beta Was this translation helpful? Give feedback.
-
Awesome - thank you for the guidance. I'll do that. |
Beta Was this translation helpful? Give feedback.
-
I think I'm seeing some problems in my ActivityPub applications related to requesting servers being strict about
content-type
of responses matching theiraccept
headers.Here's what I see in my Rocket applications. One of my components will make a request out to a server to pull in some data.
That generates a request from the receiving server back to mine to get a public verification key to confirm the authenticity of the request. That 401 response above is an indication that that request failed. The below exchange is what that key request looks like.
The key request has an
accept
header ofapplication/activity+json, application/ld+json
and my server responds with acontent-type
ofapplication/json
because it's aJson
struct:The data retrieved from the endpoint looks exactly like what I see from other ActivityPub servers, so I'm pretty sure that the data itself is not the problem. I'm left with the possibility that the mismatch in
accept
andcontent-type
may have a role. But I can't see how I can fix that. Is there a way for me to manually set thecontent-type
in Rocket?As a last resort, all of this passes through an
nginx
server (for production) or proxied through a SvelteKit server (for development). I can probably change the header there if I need to. But that's really ugly.Beta Was this translation helpful? Give feedback.
All reactions