Fork me on GitHub

is there an easy way to get the response headers when using [ "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


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


in 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


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


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


   [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
    {: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"]}))


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


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


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.


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


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


that's where i'm putting it


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.


I don't have a working http-fx ATM, but you could look into Maybe you need to check the type of response.


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


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


So @U11BV7MTK you need http-fx 0.2.0.


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