reitit icon indicating copy to clipboard operation
reitit copied to clipboard

Problem with header-parameters

Open ikitommi opened this issue 5 years ago • 4 comments

Ring lowercases request headers, which means this doesn't work:

["/"
 {:get {:parameters {:header {:Authorization s/Str}}
        :handler (fn [request]
                   {:status 200
                    :body (get-in request [:parameters :header :Authorization])})}}]

I guess there are options:

  1. header-params are declared as String, e.g. {:headers {"Authorization" string?}}
  2. as CamelCase keywords, the coercion reads them correctly {:headers {:Authorization string?}}
  3. as lower-case keywords, camel-cased for api-docs {:headers {:authorization string?}}
  4. something else

ikitommi avatar Apr 02 '19 07:04 ikitommi

  1. Header params are declared as lower-case strings {:headers {"authorization" string?}} which would match exactly what Ring provides us. (Could still HTTP-Header-Case them for documentation.)

miikka avatar Apr 02 '19 08:04 miikka

what if someone really want's to use a lowercase header like x-my-secret-token? the doc generation would do it wrong.

ikitommi avatar Apr 02 '19 08:04 ikitommi

HTTP headers are case-insensitive and a Ring-using application can't distinguish between x-my-secret-token and X-My-Secret-Token because Ring converts them to lower-case anyway, so I'd just not support that case.

miikka avatar Apr 02 '19 08:04 miikka

Hey there. Does this work with swagger-ui? I'm trying to get an "Authorization" headers field to magically appear so that I can enter a JWT token string and test my API, but I can't figure out how to do it. I'm trying the below, and everything is working with curl... Just that swagger isn't showing any way to add auth header.

:get {:summary "list offers"
         :parameters {:headers {"authorization" string?}}
         ... etc
  1. Header params are declared as lower-case strings {:headers {"authorization" string?}} which would match exactly what Ring provides us. (Could still HTTP-Header-Case them for documentation.)

shinsyotta avatar Apr 12 '20 20:04 shinsyotta