Fork me on GitHub
#re-frame
<
2019-09-01
>
dpsutton03:09:48

is there an easy way to get the response headers when using [day8.re-frame/http-fx "0.1.6"]. I'm getting a list of paginated github issues and would like to get the links headers entry which gives me pagination next and last links

eag06:09:09

I'm new to all this, but maybe using the :response-headers option ? It's mentioned in the readme for cljs-ajax.

dpsutton06:09:12

in https://github.com/JulianBirch/cljs-ajax/blob/master/README.md there's 4 usages of the word "header" and all refer to the request headers. I'm not seeing which part you're talking about

eag06:09:01

I was thinking this. :headers - a map of the HTTP headers to set with the request

dpsutton06:09:39

yeah that's the request headers. but not (easy) way to inspect the headers on the way back

dpsutton06:09:06

(:require
   [ajax.core :as ajax]
   [ajax.json :as ajax.json]
   [ajax.protocols :refer [-body -get-response-header -get-all-headers]]
   [ajax.interceptors :refer [map->ResponseFormat]])
(def json-and-header-response
  (map->ResponseFormat
    {:read (fn json-read-response-format [xhrio]
             {:body (ajax.json/read-json-native nil true (-body xhrio))
              :headers (-get-all-headers xhrio)})
     :description "JSON with headers"
     :content-type ["application/json"]}))

eag06:09:09

But you still dont get the links-headers entry in your response ?

dpsutton06:09:53

with this i do. I'm sending {:body .. headers ...} The built in version only calls your onsuccess with the parsed body

eag06:09:09

There should be a way to do that from the re-frame layer. He says this in xhrio doc. The supplied value should be an options map as defined by the simple interface ajax-request see: api docs. Except for :on-success and :on-failure. All options supported by ajax-request should be supported by this library, as it is a thin wrapper over ajax-request. Of course it goes to the other readme, which Im sure you've read a million times.

dpsutton06:09:54

that's true. this is the response reader. The standard ones just return the body. The one above is very similar to the json one (mostly cut and paste) but also includes the headers

eag07:09:32

What happens if you add those options to your re-frame version ? In the code it looks like they should pass through.

dpsutton07:09:18

that's where i'm putting it

eag07:09:27

In the code it only looks for the response from the xhrlo object. The link is dead. But here are the docs for xhrlo. There is a method to get the headers, I think the handler just ignores them. https://developers.google.com/closure/library/docs/xhrio

jahson07:09:13

I don't have a working http-fx ATM, but you could look into https://github.com/JulianBirch/cljs-ajax/blob/5c9a79dafee0a08860a28a1d818581c921517db3/src/ajax/protocols.cljc#L37. Maybe you need to check the type of response.

jahson09:09:33

I was thinking that the response will be record, but it turns out I was not attentive enough.

eag11:09:41

Yep, headers are not being passed through. Good research !

eag11:09:44

So @U11BV7MTK you need http-fx 0.2.0.

eag13:09:20

Or at least that one change. Nice to wake up to some answers. :-)