router
router copied to clipboard
axum refuses the text/plain content type
Describe the bug
not sure why but we have a request with 'Content-Type' -> 'text/plain; charset=utf-8' and an additional Authorization and X-Correlation-Id headers. We tried both csrf's unsafe_disabled: true and required_headers: [Authorization] config entries, described in https://www.apollographql.com/docs/router/configuration/csrf, but both didn't work. And the request fails because of the 'Content-Type' -> 'text/plain' with:
expected status code '200' but '415' was received with body:
"Expected request with `Content-Type: application/json`"
We tried with different versions 0.9.0 (3 and 5) not working.
Expected behavior The config should work and enable us to bypass the csrf validation somehow.
Maybe to add some information: we would to be able to accept requests with json body as text/plain. The existing GraphQL api allows that, and we need not to break existing customers when introducing federation.
I am not sure this comes from the CSRF plugin, because then you would get this error message https://github.com/apollographql/router/blob/af3209126ffee9b825b694ee6913745873e8115b/apollo-router/src/plugins/csrf.rs#L120-L122 we will look into it
ok it looks like it's the axum server that refuses this content type, not the csrf plugin, we'll see how that can work
thank you 🙏 @Geal
Thanks for opening this originally! It is unlikely that we will ever support text/plain natively in the Router for sending GraphQL requests since it seems like a fundamentally incorrect content-type for sending a GraphQL request as JSON (which we would expect to be application/json), but we believe that #1727 would provide the surface area that could enable you to do this in your own implementation.
I'm going to close this as "Working as intended", but make a reference to this issue within that enhancement issue so we can consider it an eventual implementation of that.
Hi @abernix , could you please give us some more context on how we could use https://github.com/apollographql/router/pull/1727 to implement this functionality ourselves? From what I understood, this will have to be outside the plugin customisation, but I'm not clear on how we can do this.
Hey @andraaandrus, thanks for your message!
Fortunately we are about to land https://github.com/apollographql/router/pull/2170 which will give you the tools to add a rust plugin that transforms headers, by writing a custom plugin that operates in a router_service map_request.
It should be on dev soon, and it will make it to 1.7. Feel free to try it out in the meantime!
Thanks for the update @o0Ignition0o :)