pedestal / pedestal.ions

A Pedestal Interceptor Chain provider for Datomic Ions
24 stars 6 forks source link

ion-provider should handle when the header has coll-of values. #3

Open souenzzo opened 5 years ago

souenzzo commented 5 years ago

Some middlewares¹ create headers values like {"Set-Cookie" ["foo"]}

On aws lambda, it results in

Endpoint response body before transformations: 
{
  ...pprinted and filtered the relevant content...
  "headers": {
    "Set-Cookie": [
      "foo"
    ]
  }
}

That throws: Execution failed due to configuration error: Malformed Lambda proxy response

In aws docs², it shows in examples that headers should be a (s/map-of string? string?)

In the case of cookies, it can be (string/join ";" vs), but I dont know how "any many valued" header should be joined.

I can find how jetty handle it :/

¹ https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/cookies.clj#L142 ² https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/

ddeaguiar commented 5 years ago

I dug into this and found that for servlets, Pedestal adds the header multiple times with each value, respectively. Additionally, the AWS API Gateway documentation supports passing multiple values for a header using the multiValueHeaders key in responses. This ends up adding the header multiple times for each value as well.

I'll look into how multiValueHeaders can be supported but think that will involve a change to Datomic Ions web support.

euccastro commented 5 years ago

See this for a slightly hacky workaround to this problem https://github.com/euccastro/expand-headers .

yayitswei commented 5 years ago

Can confirm @euccastro's workaround solves the issue when using API Gateway.