graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Content-Type header's value override

Open nvmxre opened this issue 1 year ago • 5 comments

Is your proposal related to a problem? Yes

I'm using Hasura to communicate with OpenStack's API. Trying to make a change to existing image instance I've encountered a problem that I can't change Content-Type header to my value, it's always transformed automatically to application/json. Accordingly to an OpenStack's API Docs it's value must be application/openstack-images-v2.1-json-patch, otherwise it will return 415 status error.

Describe the solution you'd like

The best solution would be to have an opportunity to override default values if needed.

nvmxre avatar Sep 04 '24 16:09 nvmxre

Hi @Nevemoire, Please provide additional details such as -

  • How are you using the OpenStack's API with Hasura? (Actions ?)
  • Describe the solution in terms of Metadata or console UI (if applicable).

rakeshkky avatar Sep 05 '24 06:09 rakeshkky

Hi @rakeshkky. Yes, all the communication with OpenStack is handled via Hasura Actions.

For POST, GET and DELETE calls everything works fine as far as I pass OpenStack's token via X-Auth-Token header. The problem appears when I'm trying to make a PATCH request as it's needed to pass a custom Content-Type header as I've mentioned above.

When I'm testing update Action via Hasura's API explorer, here is what I'm passing: "headers": [ { "name": "Content-Type", "value": "application/openstack-images-v2.1-json-patch" }, { "name": "X-Forwarded-Host", "value": "xxx:8080" }, { "name": "X-Forwarded-User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36" }, { "name": "X-Forwarded-Origin", "value": "http://xxx:8080" }, { "name": "x-request-id", "value": "3b9086ee-4a6f-4ede-af0b-0213e276a630" }, { "name": "X-Auth-Token", "value": "xxx" } ], but in transformed request Content-Type equals application/json, therefore I receive 415 status error from OpenStack.

Sorry if my explanation is not clear

nvmxre avatar Sep 05 '24 16:09 nvmxre

Thank you for the information. Have you checked out Request Transformation in Actions? It has a way to set the Content-Type header value. Ref: Rest Connectors

rakeshkky avatar Sep 06 '24 05:09 rakeshkky

@rakeshkky gotcha. Now I'm trying to manually import metadata where I specify request_transform as: "request_transform": { "method": "PATCH", "query_params": {}, "template_engine": "Kriti", "url": "{{$base_url}}/{{escapeUri($body.input.id)}}", "content_type": "application/openstack-images-v2.1-json-patch", "version": 1 },, but after importing it removes a content_type field. Can you please explain what am I doing wrong?

nvmxre avatar Sep 06 '24 13:09 nvmxre

Full action: { "name": "updateImage", "definition": { "handler": "http://ip:port/v2/images", "output_type": "UpdatedImage", "forward_client_headers": true, "arguments": [ { "name": "id", "type": "String!" }, { "name": "name", "type": "String" }, { "name": "size", "type": "Int" } ], "request_transform": { "method": "PATCH", "query_params": {}, "template_engine": "Kriti", "url": "{{$base_url}}/{{escapeUri($body.input.id)}}", "content_type": "application/openstack-images-v2.1-json-patch", "version": 1 }, "type": "mutation", "kind": "synchronous" } }

nvmxre avatar Sep 06 '24 13:09 nvmxre