superfaceai / one-sdk-js

1️⃣ One Node.js SDK for all the APIs you want to integrate with
https://superface.ai
MIT License
46 stars 3 forks source link

[BUG] OneSDK overrides the custom `accept` header #264

Closed jnv closed 1 year ago

jnv commented 2 years ago

Given the following http request:

  http GET "/example" {
    request {
      headers {
        Accept = "application/json"
      }
    }
    response 200 "application/json" {
      // handle correct result
    }
    response {
      // handle everything else
    }
  }

Expected Behavior

The request should be sent with accept: application/json.

Current Behavior

I see the following with DEBUG=superface:http:sensitive env:

In case I name the header in the map as accept (lowercase a), I don't see it in the debug output at all.

Possible Solution

Note that this could be an issue with debug output, I didn't test what header actually reaches the endpoint in the end.

The current implementation of the interpreter collects expected response types and passes them to the request. If any of the response handlers is missing a response type, */* is set instead. It is likely that somewhere down the line, the passed-in accept parameter overrides the user-provider header.

Your Environment

freaz commented 1 year ago

Finally got to this and definitely something odd is happening there.

image

And it seems it is caused by case sensitivity when resolving headers.

image