Working production build in docs subdirectory.

This commit is contained in:
Simon Brooke 2020-02-27 09:35:17 +00:00
parent bb7be028e6
commit a5204c66b9
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
644 changed files with 134256 additions and 53616 deletions

View file

@ -0,0 +1,369 @@
(ns cljs-http.client
(:refer-clojure :exclude [get])
(:require [cljs-http.core :as core]
[cljs-http.util :as util]
[cljs.core.async :as async :refer [<! chan close! put!]]
[cljs.reader :refer [read-string]]
[clojure.string :refer [blank? join split]]
[goog.Uri :as uri]
[no.en.core :refer [url-encode url-decode]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn if-pos [v]
(if (and v (pos? v)) v))
(defn- acc-param [o v]
(cond
(coll? o) (conj o v)
(some? o) [o v]
:else v))
(defn parse-query-params
"Parse `s` as query params and return a hash map."
[s]
(if-not (blank? s)
(reduce
#(let [[k v] (split %2 #"=")]
(update %1
(keyword (url-decode k))
acc-param
(url-decode v)))
{} (split (str s) #"&"))))
(defn parse-url
"Parse `url` into a hash map."
[url]
(if-not (blank? url)
(let [uri (uri/parse url)
query-data (.getQueryData uri)]
{:scheme (keyword (.getScheme uri))
:server-name (.getDomain uri)
:server-port (if-pos (.getPort uri))
:uri (.getPath uri)
:query-string (if-not (.isEmpty query-data)
(str query-data))
:query-params (if-not (.isEmpty query-data)
(parse-query-params (str query-data)))})))
(def unexceptional-status?
#{200 201 202 203 204 205 206 207 300 301 302 303 307})
(defn- encode-val [k v]
(str (url-encode (name k)) "=" (url-encode (str v))))
(defn- encode-vals [k vs]
(->>
vs
(map #(encode-val k %))
(join "&")))
(defn- encode-param [[k v]]
(if (coll? v)
(encode-vals k v)
(encode-val k v)))
(defn generate-query-string [params]
(->>
params
(map encode-param)
(join "&")))
(def regex-char-esc-smap
(let [esc-chars "()*&^%$#!+"]
(zipmap esc-chars
(map #(str "\\" %) esc-chars))))
(defn escape-special
"Escape special characters -- for content-type."
[string]
(->> string
(replace regex-char-esc-smap)
(reduce str)))
(defn decode-body
"Decocde the :body of `response` with `decode-fn` if the content type matches."
[response decode-fn content-type request-method]
(if (and (not= :head request-method)
(not= 204 (:status response))
(re-find (re-pattern (str "(?i)" (escape-special content-type)))
(str (clojure.core/get (:headers response) "content-type" ""))))
(update-in response [:body] decode-fn)
response))
(defn wrap-edn-params
"Encode :edn-params in the `request` :body and set the appropriate
Content Type header."
[client]
(fn [request]
(if-let [params (:edn-params request)]
(let [headers (merge {"content-type" "application/edn"} (:headers request))]
(-> (dissoc request :edn-params)
(assoc :body (pr-str params))
(assoc :headers headers)
(client)))
(client request))))
(defn wrap-edn-response
"Decode application/edn responses."
[client]
(fn [request]
(-> #(decode-body % read-string "application/edn" (:request-method request))
(async/map [(client request)]))))
(defn wrap-default-headers
[client & [default-headers]]
(fn [request]
(if-let [default-headers (or (:default-headers request) default-headers)]
(client (assoc request :default-headers default-headers))
(client request))))
(defn wrap-accept
[client & [accept]]
(fn [request]
(if-let [accept (or (:accept request) accept)]
(client (assoc-in request [:headers "accept"] accept))
(client request))))
(defn wrap-content-type
[client & [content-type]]
(fn [request]
(if-let [content-type (or (:content-type request) content-type)]
(client (assoc-in request [:headers "content-type"] content-type))
(client request))))
(def ^{:private true} default-transit-opts
{:encoding :json :encoding-opts {}
:decoding :json :decoding-opts {}})
(defn wrap-transit-params
"Encode :transit-params in the `request` :body and set the appropriate
Content Type header.
A :transit-opts map can be optionally provided with the following keys:
:encoding #{:json, :json-verbose}
:decoding #{:json, :json-verbose}
:encoding/decoding-opts appropriate map of options to be passed to
transit writer/reader, respectively."
[client]
(fn [request]
(if-let [params (:transit-params request)]
(let [{:keys [encoding encoding-opts]} (merge default-transit-opts
(:transit-opts request))
headers (merge {"content-type" "application/transit+json"} (:headers request))]
(-> (dissoc request :transit-params)
(assoc :body (util/transit-encode params encoding encoding-opts))
(assoc :headers headers)
(client)))
(client request))))
(defn wrap-transit-response
"Decode application/transit+json responses."
[client]
(fn [request]
(let [{:keys [decoding decoding-opts]} (merge default-transit-opts
(:transit-opts request))
transit-decode #(util/transit-decode % decoding decoding-opts)]
(-> #(decode-body % transit-decode "application/transit+json" (:request-method request))
(async/map [(client request)])))))
(defn wrap-json-params
"Encode :json-params in the `request` :body and set the appropriate
Content Type header."
[client]
(fn [request]
(if-let [params (:json-params request)]
(let [headers (merge {"content-type" "application/json"} (:headers request))]
(-> (dissoc request :json-params)
(assoc :body (util/json-encode params))
(assoc :headers headers)
(client)))
(client request))))
(defn wrap-json-response
"Decode application/json responses."
[client]
(fn [request]
(-> #(decode-body % util/json-decode "application/json" (:request-method request))
(async/map [(client request)]))))
(defn wrap-query-params [client]
(fn [{:keys [query-params] :as req}]
(if query-params
(client (-> req (dissoc :query-params)
(assoc :query-string
(generate-query-string query-params))))
(client req))))
(defn wrap-form-params [client]
(fn [{:keys [form-params request-method headers] :as request}]
(if (and form-params (#{:post :put :patch :delete} request-method))
(let [headers (merge {"content-type" "application/x-www-form-urlencoded"} headers)]
(client (-> request
(dissoc :form-params)
(assoc :body (generate-query-string form-params))
(assoc :headers headers))))
(client request))))
(defn generate-form-data [params]
(let [form-data (js/FormData.)]
(doseq [[k v] params]
(if (coll? v)
(.append form-data (name k) (first v) (second v))
(.append form-data (name k) v)))
form-data))
(defn wrap-multipart-params [client]
(fn [{:keys [multipart-params request-method] :as request}]
(if (and multipart-params (#{:post :put :patch :delete} request-method))
(client (-> request
(dissoc :multipart-params)
(assoc :body (generate-form-data multipart-params))))
(client request))))
(defn wrap-method [client]
(fn [req]
(if-let [m (:method req)]
(client (-> req (dissoc :method)
(assoc :request-method m)))
(client req))))
(defn wrap-server-name [client server-name]
#(client (assoc %1 :server-name server-name)))
(defn wrap-url [client]
(fn [{:keys [query-params] :as req}]
(if-let [spec (parse-url (:url req))]
(client (-> (merge req spec)
(dissoc :url)
(update-in [:query-params] #(merge %1 query-params))))
(client req))))
(defn wrap-basic-auth
"Middleware converting the :basic-auth option or `credentials` into
an Authorization header."
[client & [credentials]]
(fn [req]
(let [credentials (or (:basic-auth req) credentials)]
(if-not (empty? credentials)
(client (-> (dissoc req :basic-auth)
(assoc-in [:headers "authorization"] (util/basic-auth credentials))))
(client req)))))
(defn wrap-oauth
"Middleware converting the :oauth-token option into an Authorization header."
[client]
(fn [req]
(if-let [oauth-token (:oauth-token req)]
(client (-> req (dissoc :oauth-token)
(assoc-in [:headers "authorization"]
(str "Bearer " oauth-token))))
(client req))))
(defn wrap-channel-from-request-map
"Pipe the response-channel into the request-map's
custom channel (e.g. to enable transducers)"
[client]
(fn [request]
(if-let [custom-channel (:channel request)]
(async/pipe (client request) custom-channel)
(client request))))
(defn wrap-request
"Returns a batteries-included HTTP request function coresponding to the given
core client. See client/request"
[request]
(-> request
wrap-accept
wrap-form-params
wrap-multipart-params
wrap-edn-params
wrap-edn-response
wrap-transit-params
wrap-transit-response
wrap-json-params
wrap-json-response
wrap-content-type
wrap-query-params
wrap-basic-auth
wrap-oauth
wrap-method
wrap-url
wrap-channel-from-request-map
wrap-default-headers))
(def #^{:doc
"Executes the HTTP request corresponding to the given map and returns the
response map for corresponding to the resulting HTTP response.
In addition to the standard Ring request keys, the following keys are also
recognized:
* :url
* :method
* :query-params"}
request (wrap-request core/request))
(defn delete
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :delete :url url})))
(defn get
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :get :url url})))
(defn head
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :head :url url})))
(defn jsonp
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :jsonp :url url})))
(defn move
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :move :url url})))
(defn options
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :options :url url})))
(defn patch
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :patch :url url})))
(defn post
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :post :url url})))
(defn put
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :put :url url})))
(comment
(ns example.core
(:require [cljs-http.client :as http]
[cljs.core.async :refer [<!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(go (prn (map :login (:body (<! (get "https://api.github.com/users"))))))
(go (prn (:status (<! (get "http://api.burningswell.dev/continents")))))
(go (prn (map :name (:body (<! (get "http://api.burningswell.dev/continents"))))))
(go (let [response (<! (get "https://api.github.com/users"))]
(prn (:status response))
(prn (map :login (:body response)))))
(go (prn (<! (get "http://api.burningswell.dev/continents")))))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,991 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('cljs_http.client');
goog.require('cljs.core');
goog.require('cljs_http.core');
goog.require('cljs_http.util');
goog.require('cljs.core.async');
goog.require('cljs.reader');
goog.require('clojure.string');
goog.require('goog.Uri');
goog.require('no.en.core');
cljs_http.client.if_pos = (function cljs_http$client$if_pos(v){
if(cljs.core.truth_((function (){var and__4120__auto__ = v;
if(cljs.core.truth_(and__4120__auto__)){
return (v > (0));
} else {
return and__4120__auto__;
}
})())){
return v;
} else {
return null;
}
});
cljs_http.client.acc_param = (function cljs_http$client$acc_param(o,v){
if(cljs.core.coll_QMARK_.call(null,o)){
return cljs.core.conj.call(null,o,v);
} else {
if((!((o == null)))){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [o,v], null);
} else {
return v;
}
}
});
/**
* Parse `s` as query params and return a hash map.
*/
cljs_http.client.parse_query_params = (function cljs_http$client$parse_query_params(s){
if((!(clojure.string.blank_QMARK_.call(null,s)))){
return cljs.core.reduce.call(null,(function (p1__25690_SHARP_,p2__25689_SHARP_){
var vec__25691 = clojure.string.split.call(null,p2__25689_SHARP_,/=/);
var k = cljs.core.nth.call(null,vec__25691,(0),null);
var v = cljs.core.nth.call(null,vec__25691,(1),null);
return cljs.core.update.call(null,p1__25690_SHARP_,cljs.core.keyword.call(null,no.en.core.url_decode.call(null,k)),cljs_http.client.acc_param,no.en.core.url_decode.call(null,v));
}),cljs.core.PersistentArrayMap.EMPTY,clojure.string.split.call(null,cljs.core.str.cljs$core$IFn$_invoke$arity$1(s),/&/));
} else {
return null;
}
});
/**
* Parse `url` into a hash map.
*/
cljs_http.client.parse_url = (function cljs_http$client$parse_url(url){
if((!(clojure.string.blank_QMARK_.call(null,url)))){
var uri = goog.Uri.parse(url);
var query_data = uri.getQueryData();
return new cljs.core.PersistentArrayMap(null, 6, [new cljs.core.Keyword(null,"scheme","scheme",90199613),cljs.core.keyword.call(null,uri.getScheme()),new cljs.core.Keyword(null,"server-name","server-name",-1012104295),uri.getDomain(),new cljs.core.Keyword(null,"server-port","server-port",663745648),cljs_http.client.if_pos.call(null,uri.getPort()),new cljs.core.Keyword(null,"uri","uri",-774711847),uri.getPath(),new cljs.core.Keyword(null,"query-string","query-string",-1018845061),((cljs.core.not.call(null,query_data.isEmpty()))?cljs.core.str.cljs$core$IFn$_invoke$arity$1(query_data):null),new cljs.core.Keyword(null,"query-params","query-params",900640534),((cljs.core.not.call(null,query_data.isEmpty()))?cljs_http.client.parse_query_params.call(null,cljs.core.str.cljs$core$IFn$_invoke$arity$1(query_data)):null)], null);
} else {
return null;
}
});
cljs_http.client.unexceptional_status_QMARK_ = new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 13, [(205),null,(206),null,(300),null,(204),null,(307),null,(303),null,(301),null,(201),null,(302),null,(202),null,(200),null,(203),null,(207),null], null), null);
cljs_http.client.encode_val = (function cljs_http$client$encode_val(k,v){
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1(no.en.core.url_encode.call(null,cljs.core.name.call(null,k))),"=",cljs.core.str.cljs$core$IFn$_invoke$arity$1(no.en.core.url_encode.call(null,cljs.core.str.cljs$core$IFn$_invoke$arity$1(v)))].join('');
});
cljs_http.client.encode_vals = (function cljs_http$client$encode_vals(k,vs){
return clojure.string.join.call(null,"&",cljs.core.map.call(null,(function (p1__25694_SHARP_){
return cljs_http.client.encode_val.call(null,k,p1__25694_SHARP_);
}),vs));
});
cljs_http.client.encode_param = (function cljs_http$client$encode_param(p__25695){
var vec__25696 = p__25695;
var k = cljs.core.nth.call(null,vec__25696,(0),null);
var v = cljs.core.nth.call(null,vec__25696,(1),null);
if(cljs.core.coll_QMARK_.call(null,v)){
return cljs_http.client.encode_vals.call(null,k,v);
} else {
return cljs_http.client.encode_val.call(null,k,v);
}
});
cljs_http.client.generate_query_string = (function cljs_http$client$generate_query_string(params){
return clojure.string.join.call(null,"&",cljs.core.map.call(null,cljs_http.client.encode_param,params));
});
cljs_http.client.regex_char_esc_smap = (function (){var esc_chars = "()*&^%$#!+";
return cljs.core.zipmap.call(null,esc_chars,cljs.core.map.call(null,((function (esc_chars){
return (function (p1__25699_SHARP_){
return ["\\",cljs.core.str.cljs$core$IFn$_invoke$arity$1(p1__25699_SHARP_)].join('');
});})(esc_chars))
,esc_chars));
})();
/**
* Escape special characters -- for content-type.
*/
cljs_http.client.escape_special = (function cljs_http$client$escape_special(string){
return cljs.core.reduce.call(null,cljs.core.str,cljs.core.replace.call(null,cljs_http.client.regex_char_esc_smap,string));
});
/**
* Decocde the :body of `response` with `decode-fn` if the content type matches.
*/
cljs_http.client.decode_body = (function cljs_http$client$decode_body(response,decode_fn,content_type,request_method){
if(cljs.core.truth_((function (){var and__4120__auto__ = cljs.core.not_EQ_.call(null,new cljs.core.Keyword(null,"head","head",-771383919),request_method);
if(and__4120__auto__){
var and__4120__auto____$1 = cljs.core.not_EQ_.call(null,(204),new cljs.core.Keyword(null,"status","status",-1997798413).cljs$core$IFn$_invoke$arity$1(response));
if(and__4120__auto____$1){
return cljs.core.re_find.call(null,cljs.core.re_pattern.call(null,["(?i)",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs_http.client.escape_special.call(null,content_type))].join('')),cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.get.call(null,new cljs.core.Keyword(null,"headers","headers",-835030129).cljs$core$IFn$_invoke$arity$1(response),"content-type","")));
} else {
return and__4120__auto____$1;
}
} else {
return and__4120__auto__;
}
})())){
return cljs.core.update_in.call(null,response,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"body","body",-2049205669)], null),decode_fn);
} else {
return response;
}
});
/**
* Encode :edn-params in the `request` :body and set the appropriate
* Content Type header.
*/
cljs_http.client.wrap_edn_params = (function cljs_http$client$wrap_edn_params(client){
return (function (request){
var temp__5718__auto__ = new cljs.core.Keyword(null,"edn-params","edn-params",894273052).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(temp__5718__auto__)){
var params = temp__5718__auto__;
var headers = cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 1, ["content-type","application/edn"], null),new cljs.core.Keyword(null,"headers","headers",-835030129).cljs$core$IFn$_invoke$arity$1(request));
return client.call(null,cljs.core.assoc.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,request,new cljs.core.Keyword(null,"edn-params","edn-params",894273052)),new cljs.core.Keyword(null,"body","body",-2049205669),cljs.core.pr_str.call(null,params)),new cljs.core.Keyword(null,"headers","headers",-835030129),headers));
} else {
return client.call(null,request);
}
});
});
/**
* Decode application/edn responses.
*/
cljs_http.client.wrap_edn_response = (function cljs_http$client$wrap_edn_response(client){
return (function (request){
return cljs.core.async.map.call(null,(function (p1__25700_SHARP_){
return cljs_http.client.decode_body.call(null,p1__25700_SHARP_,cljs.reader.read_string,"application/edn",new cljs.core.Keyword(null,"request-method","request-method",1764796830).cljs$core$IFn$_invoke$arity$1(request));
}),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [client.call(null,request)], null));
});
});
cljs_http.client.wrap_default_headers = (function cljs_http$client$wrap_default_headers(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25707 = arguments.length;
var i__4731__auto___25708 = (0);
while(true){
if((i__4731__auto___25708 < len__4730__auto___25707)){
args__4736__auto__.push((arguments[i__4731__auto___25708]));
var G__25709 = (i__4731__auto___25708 + (1));
i__4731__auto___25708 = G__25709;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.wrap_default_headers.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.wrap_default_headers.cljs$core$IFn$_invoke$arity$variadic = (function (client,p__25703){
var vec__25704 = p__25703;
var default_headers = cljs.core.nth.call(null,vec__25704,(0),null);
return ((function (vec__25704,default_headers){
return (function (request){
var temp__5718__auto__ = (function (){var or__4131__auto__ = new cljs.core.Keyword(null,"default-headers","default-headers",-43146094).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return default_headers;
}
})();
if(cljs.core.truth_(temp__5718__auto__)){
var default_headers__$1 = temp__5718__auto__;
return client.call(null,cljs.core.assoc.call(null,request,new cljs.core.Keyword(null,"default-headers","default-headers",-43146094),default_headers__$1));
} else {
return client.call(null,request);
}
});
;})(vec__25704,default_headers))
});
cljs_http.client.wrap_default_headers.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.wrap_default_headers.cljs$lang$applyTo = (function (seq25701){
var G__25702 = cljs.core.first.call(null,seq25701);
var seq25701__$1 = cljs.core.next.call(null,seq25701);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25702,seq25701__$1);
});
cljs_http.client.wrap_accept = (function cljs_http$client$wrap_accept(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25716 = arguments.length;
var i__4731__auto___25717 = (0);
while(true){
if((i__4731__auto___25717 < len__4730__auto___25716)){
args__4736__auto__.push((arguments[i__4731__auto___25717]));
var G__25718 = (i__4731__auto___25717 + (1));
i__4731__auto___25717 = G__25718;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.wrap_accept.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.wrap_accept.cljs$core$IFn$_invoke$arity$variadic = (function (client,p__25712){
var vec__25713 = p__25712;
var accept = cljs.core.nth.call(null,vec__25713,(0),null);
return ((function (vec__25713,accept){
return (function (request){
var temp__5718__auto__ = (function (){var or__4131__auto__ = new cljs.core.Keyword(null,"accept","accept",1874130431).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return accept;
}
})();
if(cljs.core.truth_(temp__5718__auto__)){
var accept__$1 = temp__5718__auto__;
return client.call(null,cljs.core.assoc_in.call(null,request,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"headers","headers",-835030129),"accept"], null),accept__$1));
} else {
return client.call(null,request);
}
});
;})(vec__25713,accept))
});
cljs_http.client.wrap_accept.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.wrap_accept.cljs$lang$applyTo = (function (seq25710){
var G__25711 = cljs.core.first.call(null,seq25710);
var seq25710__$1 = cljs.core.next.call(null,seq25710);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25711,seq25710__$1);
});
cljs_http.client.wrap_content_type = (function cljs_http$client$wrap_content_type(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25725 = arguments.length;
var i__4731__auto___25726 = (0);
while(true){
if((i__4731__auto___25726 < len__4730__auto___25725)){
args__4736__auto__.push((arguments[i__4731__auto___25726]));
var G__25727 = (i__4731__auto___25726 + (1));
i__4731__auto___25726 = G__25727;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.wrap_content_type.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.wrap_content_type.cljs$core$IFn$_invoke$arity$variadic = (function (client,p__25721){
var vec__25722 = p__25721;
var content_type = cljs.core.nth.call(null,vec__25722,(0),null);
return ((function (vec__25722,content_type){
return (function (request){
var temp__5718__auto__ = (function (){var or__4131__auto__ = new cljs.core.Keyword(null,"content-type","content-type",-508222634).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return content_type;
}
})();
if(cljs.core.truth_(temp__5718__auto__)){
var content_type__$1 = temp__5718__auto__;
return client.call(null,cljs.core.assoc_in.call(null,request,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"headers","headers",-835030129),"content-type"], null),content_type__$1));
} else {
return client.call(null,request);
}
});
;})(vec__25722,content_type))
});
cljs_http.client.wrap_content_type.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.wrap_content_type.cljs$lang$applyTo = (function (seq25719){
var G__25720 = cljs.core.first.call(null,seq25719);
var seq25719__$1 = cljs.core.next.call(null,seq25719);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25720,seq25719__$1);
});
cljs_http.client.default_transit_opts = new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"encoding","encoding",1728578272),new cljs.core.Keyword(null,"json","json",1279968570),new cljs.core.Keyword(null,"encoding-opts","encoding-opts",-1805664631),cljs.core.PersistentArrayMap.EMPTY,new cljs.core.Keyword(null,"decoding","decoding",-568180903),new cljs.core.Keyword(null,"json","json",1279968570),new cljs.core.Keyword(null,"decoding-opts","decoding-opts",1050289140),cljs.core.PersistentArrayMap.EMPTY], null);
/**
* Encode :transit-params in the `request` :body and set the appropriate
* Content Type header.
*
* A :transit-opts map can be optionally provided with the following keys:
*
* :encoding #{:json, :json-verbose}
* :decoding #{:json, :json-verbose}
* :encoding/decoding-opts appropriate map of options to be passed to
* transit writer/reader, respectively.
*/
cljs_http.client.wrap_transit_params = (function cljs_http$client$wrap_transit_params(client){
return (function (request){
var temp__5718__auto__ = new cljs.core.Keyword(null,"transit-params","transit-params",357261095).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(temp__5718__auto__)){
var params = temp__5718__auto__;
var map__25728 = cljs.core.merge.call(null,cljs_http.client.default_transit_opts,new cljs.core.Keyword(null,"transit-opts","transit-opts",1104386010).cljs$core$IFn$_invoke$arity$1(request));
var map__25728__$1 = (((((!((map__25728 == null))))?(((((map__25728.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25728.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25728):map__25728);
var encoding = cljs.core.get.call(null,map__25728__$1,new cljs.core.Keyword(null,"encoding","encoding",1728578272));
var encoding_opts = cljs.core.get.call(null,map__25728__$1,new cljs.core.Keyword(null,"encoding-opts","encoding-opts",-1805664631));
var headers = cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 1, ["content-type","application/transit+json"], null),new cljs.core.Keyword(null,"headers","headers",-835030129).cljs$core$IFn$_invoke$arity$1(request));
return client.call(null,cljs.core.assoc.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,request,new cljs.core.Keyword(null,"transit-params","transit-params",357261095)),new cljs.core.Keyword(null,"body","body",-2049205669),cljs_http.util.transit_encode.call(null,params,encoding,encoding_opts)),new cljs.core.Keyword(null,"headers","headers",-835030129),headers));
} else {
return client.call(null,request);
}
});
});
/**
* Decode application/transit+json responses.
*/
cljs_http.client.wrap_transit_response = (function cljs_http$client$wrap_transit_response(client){
return (function (request){
var map__25732 = cljs.core.merge.call(null,cljs_http.client.default_transit_opts,new cljs.core.Keyword(null,"transit-opts","transit-opts",1104386010).cljs$core$IFn$_invoke$arity$1(request));
var map__25732__$1 = (((((!((map__25732 == null))))?(((((map__25732.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25732.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25732):map__25732);
var decoding = cljs.core.get.call(null,map__25732__$1,new cljs.core.Keyword(null,"decoding","decoding",-568180903));
var decoding_opts = cljs.core.get.call(null,map__25732__$1,new cljs.core.Keyword(null,"decoding-opts","decoding-opts",1050289140));
var transit_decode = ((function (map__25732,map__25732__$1,decoding,decoding_opts){
return (function (p1__25730_SHARP_){
return cljs_http.util.transit_decode.call(null,p1__25730_SHARP_,decoding,decoding_opts);
});})(map__25732,map__25732__$1,decoding,decoding_opts))
;
return cljs.core.async.map.call(null,((function (map__25732,map__25732__$1,decoding,decoding_opts,transit_decode){
return (function (p1__25731_SHARP_){
return cljs_http.client.decode_body.call(null,p1__25731_SHARP_,transit_decode,"application/transit+json",new cljs.core.Keyword(null,"request-method","request-method",1764796830).cljs$core$IFn$_invoke$arity$1(request));
});})(map__25732,map__25732__$1,decoding,decoding_opts,transit_decode))
,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [client.call(null,request)], null));
});
});
/**
* Encode :json-params in the `request` :body and set the appropriate
* Content Type header.
*/
cljs_http.client.wrap_json_params = (function cljs_http$client$wrap_json_params(client){
return (function (request){
var temp__5718__auto__ = new cljs.core.Keyword(null,"json-params","json-params",-1112693596).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(temp__5718__auto__)){
var params = temp__5718__auto__;
var headers = cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 1, ["content-type","application/json"], null),new cljs.core.Keyword(null,"headers","headers",-835030129).cljs$core$IFn$_invoke$arity$1(request));
return client.call(null,cljs.core.assoc.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,request,new cljs.core.Keyword(null,"json-params","json-params",-1112693596)),new cljs.core.Keyword(null,"body","body",-2049205669),cljs_http.util.json_encode.call(null,params)),new cljs.core.Keyword(null,"headers","headers",-835030129),headers));
} else {
return client.call(null,request);
}
});
});
/**
* Decode application/json responses.
*/
cljs_http.client.wrap_json_response = (function cljs_http$client$wrap_json_response(client){
return (function (request){
return cljs.core.async.map.call(null,(function (p1__25734_SHARP_){
return cljs_http.client.decode_body.call(null,p1__25734_SHARP_,cljs_http.util.json_decode,"application/json",new cljs.core.Keyword(null,"request-method","request-method",1764796830).cljs$core$IFn$_invoke$arity$1(request));
}),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [client.call(null,request)], null));
});
});
cljs_http.client.wrap_query_params = (function cljs_http$client$wrap_query_params(client){
return (function (p__25735){
var map__25736 = p__25735;
var map__25736__$1 = (((((!((map__25736 == null))))?(((((map__25736.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25736.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25736):map__25736);
var req = map__25736__$1;
var query_params = cljs.core.get.call(null,map__25736__$1,new cljs.core.Keyword(null,"query-params","query-params",900640534));
if(cljs.core.truth_(query_params)){
return client.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,req,new cljs.core.Keyword(null,"query-params","query-params",900640534)),new cljs.core.Keyword(null,"query-string","query-string",-1018845061),cljs_http.client.generate_query_string.call(null,query_params)));
} else {
return client.call(null,req);
}
});
});
cljs_http.client.wrap_form_params = (function cljs_http$client$wrap_form_params(client){
return (function (p__25738){
var map__25739 = p__25738;
var map__25739__$1 = (((((!((map__25739 == null))))?(((((map__25739.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25739.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25739):map__25739);
var request = map__25739__$1;
var form_params = cljs.core.get.call(null,map__25739__$1,new cljs.core.Keyword(null,"form-params","form-params",1884296467));
var request_method = cljs.core.get.call(null,map__25739__$1,new cljs.core.Keyword(null,"request-method","request-method",1764796830));
var headers = cljs.core.get.call(null,map__25739__$1,new cljs.core.Keyword(null,"headers","headers",-835030129));
if(cljs.core.truth_((function (){var and__4120__auto__ = form_params;
if(cljs.core.truth_(and__4120__auto__)){
return new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"patch","patch",380775109),null,new cljs.core.Keyword(null,"delete","delete",-1768633620),null,new cljs.core.Keyword(null,"post","post",269697687),null,new cljs.core.Keyword(null,"put","put",1299772570),null], null), null).call(null,request_method);
} else {
return and__4120__auto__;
}
})())){
var headers__$1 = cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 1, ["content-type","application/x-www-form-urlencoded"], null),headers);
return client.call(null,cljs.core.assoc.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,request,new cljs.core.Keyword(null,"form-params","form-params",1884296467)),new cljs.core.Keyword(null,"body","body",-2049205669),cljs_http.client.generate_query_string.call(null,form_params)),new cljs.core.Keyword(null,"headers","headers",-835030129),headers__$1));
} else {
return client.call(null,request);
}
});
});
cljs_http.client.generate_form_data = (function cljs_http$client$generate_form_data(params){
var form_data = (new FormData());
var seq__25741_25757 = cljs.core.seq.call(null,params);
var chunk__25742_25758 = null;
var count__25743_25759 = (0);
var i__25744_25760 = (0);
while(true){
if((i__25744_25760 < count__25743_25759)){
var vec__25751_25761 = cljs.core._nth.call(null,chunk__25742_25758,i__25744_25760);
var k_25762 = cljs.core.nth.call(null,vec__25751_25761,(0),null);
var v_25763 = cljs.core.nth.call(null,vec__25751_25761,(1),null);
if(cljs.core.coll_QMARK_.call(null,v_25763)){
form_data.append(cljs.core.name.call(null,k_25762),cljs.core.first.call(null,v_25763),cljs.core.second.call(null,v_25763));
} else {
form_data.append(cljs.core.name.call(null,k_25762),v_25763);
}
var G__25764 = seq__25741_25757;
var G__25765 = chunk__25742_25758;
var G__25766 = count__25743_25759;
var G__25767 = (i__25744_25760 + (1));
seq__25741_25757 = G__25764;
chunk__25742_25758 = G__25765;
count__25743_25759 = G__25766;
i__25744_25760 = G__25767;
continue;
} else {
var temp__5720__auto___25768 = cljs.core.seq.call(null,seq__25741_25757);
if(temp__5720__auto___25768){
var seq__25741_25769__$1 = temp__5720__auto___25768;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__25741_25769__$1)){
var c__4550__auto___25770 = cljs.core.chunk_first.call(null,seq__25741_25769__$1);
var G__25771 = cljs.core.chunk_rest.call(null,seq__25741_25769__$1);
var G__25772 = c__4550__auto___25770;
var G__25773 = cljs.core.count.call(null,c__4550__auto___25770);
var G__25774 = (0);
seq__25741_25757 = G__25771;
chunk__25742_25758 = G__25772;
count__25743_25759 = G__25773;
i__25744_25760 = G__25774;
continue;
} else {
var vec__25754_25775 = cljs.core.first.call(null,seq__25741_25769__$1);
var k_25776 = cljs.core.nth.call(null,vec__25754_25775,(0),null);
var v_25777 = cljs.core.nth.call(null,vec__25754_25775,(1),null);
if(cljs.core.coll_QMARK_.call(null,v_25777)){
form_data.append(cljs.core.name.call(null,k_25776),cljs.core.first.call(null,v_25777),cljs.core.second.call(null,v_25777));
} else {
form_data.append(cljs.core.name.call(null,k_25776),v_25777);
}
var G__25778 = cljs.core.next.call(null,seq__25741_25769__$1);
var G__25779 = null;
var G__25780 = (0);
var G__25781 = (0);
seq__25741_25757 = G__25778;
chunk__25742_25758 = G__25779;
count__25743_25759 = G__25780;
i__25744_25760 = G__25781;
continue;
}
} else {
}
}
break;
}
return form_data;
});
cljs_http.client.wrap_multipart_params = (function cljs_http$client$wrap_multipart_params(client){
return (function (p__25782){
var map__25783 = p__25782;
var map__25783__$1 = (((((!((map__25783 == null))))?(((((map__25783.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25783.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25783):map__25783);
var request = map__25783__$1;
var multipart_params = cljs.core.get.call(null,map__25783__$1,new cljs.core.Keyword(null,"multipart-params","multipart-params",-1033508707));
var request_method = cljs.core.get.call(null,map__25783__$1,new cljs.core.Keyword(null,"request-method","request-method",1764796830));
if(cljs.core.truth_((function (){var and__4120__auto__ = multipart_params;
if(cljs.core.truth_(and__4120__auto__)){
return new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"patch","patch",380775109),null,new cljs.core.Keyword(null,"delete","delete",-1768633620),null,new cljs.core.Keyword(null,"post","post",269697687),null,new cljs.core.Keyword(null,"put","put",1299772570),null], null), null).call(null,request_method);
} else {
return and__4120__auto__;
}
})())){
return client.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,request,new cljs.core.Keyword(null,"multipart-params","multipart-params",-1033508707)),new cljs.core.Keyword(null,"body","body",-2049205669),cljs_http.client.generate_form_data.call(null,multipart_params)));
} else {
return client.call(null,request);
}
});
});
cljs_http.client.wrap_method = (function cljs_http$client$wrap_method(client){
return (function (req){
var temp__5718__auto__ = new cljs.core.Keyword(null,"method","method",55703592).cljs$core$IFn$_invoke$arity$1(req);
if(cljs.core.truth_(temp__5718__auto__)){
var m = temp__5718__auto__;
return client.call(null,cljs.core.assoc.call(null,cljs.core.dissoc.call(null,req,new cljs.core.Keyword(null,"method","method",55703592)),new cljs.core.Keyword(null,"request-method","request-method",1764796830),m));
} else {
return client.call(null,req);
}
});
});
cljs_http.client.wrap_server_name = (function cljs_http$client$wrap_server_name(client,server_name){
return (function (p1__25785_SHARP_){
return client.call(null,cljs.core.assoc.call(null,p1__25785_SHARP_,new cljs.core.Keyword(null,"server-name","server-name",-1012104295),server_name));
});
});
cljs_http.client.wrap_url = (function cljs_http$client$wrap_url(client){
return (function (p__25787){
var map__25788 = p__25787;
var map__25788__$1 = (((((!((map__25788 == null))))?(((((map__25788.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25788.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25788):map__25788);
var req = map__25788__$1;
var query_params = cljs.core.get.call(null,map__25788__$1,new cljs.core.Keyword(null,"query-params","query-params",900640534));
var temp__5718__auto__ = cljs_http.client.parse_url.call(null,new cljs.core.Keyword(null,"url","url",276297046).cljs$core$IFn$_invoke$arity$1(req));
if(cljs.core.truth_(temp__5718__auto__)){
var spec = temp__5718__auto__;
return client.call(null,cljs.core.update_in.call(null,cljs.core.dissoc.call(null,cljs.core.merge.call(null,req,spec),new cljs.core.Keyword(null,"url","url",276297046)),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"query-params","query-params",900640534)], null),((function (spec,temp__5718__auto__,map__25788,map__25788__$1,req,query_params){
return (function (p1__25786_SHARP_){
return cljs.core.merge.call(null,p1__25786_SHARP_,query_params);
});})(spec,temp__5718__auto__,map__25788,map__25788__$1,req,query_params))
));
} else {
return client.call(null,req);
}
});
});
/**
* Middleware converting the :basic-auth option or `credentials` into
* an Authorization header.
*/
cljs_http.client.wrap_basic_auth = (function cljs_http$client$wrap_basic_auth(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25796 = arguments.length;
var i__4731__auto___25797 = (0);
while(true){
if((i__4731__auto___25797 < len__4730__auto___25796)){
args__4736__auto__.push((arguments[i__4731__auto___25797]));
var G__25798 = (i__4731__auto___25797 + (1));
i__4731__auto___25797 = G__25798;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.wrap_basic_auth.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.wrap_basic_auth.cljs$core$IFn$_invoke$arity$variadic = (function (client,p__25792){
var vec__25793 = p__25792;
var credentials = cljs.core.nth.call(null,vec__25793,(0),null);
return ((function (vec__25793,credentials){
return (function (req){
var credentials__$1 = (function (){var or__4131__auto__ = new cljs.core.Keyword(null,"basic-auth","basic-auth",-673163332).cljs$core$IFn$_invoke$arity$1(req);
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return credentials;
}
})();
if((!(cljs.core.empty_QMARK_.call(null,credentials__$1)))){
return client.call(null,cljs.core.assoc_in.call(null,cljs.core.dissoc.call(null,req,new cljs.core.Keyword(null,"basic-auth","basic-auth",-673163332)),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"headers","headers",-835030129),"authorization"], null),cljs_http.util.basic_auth.call(null,credentials__$1)));
} else {
return client.call(null,req);
}
});
;})(vec__25793,credentials))
});
cljs_http.client.wrap_basic_auth.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.wrap_basic_auth.cljs$lang$applyTo = (function (seq25790){
var G__25791 = cljs.core.first.call(null,seq25790);
var seq25790__$1 = cljs.core.next.call(null,seq25790);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25791,seq25790__$1);
});
/**
* Middleware converting the :oauth-token option into an Authorization header.
*/
cljs_http.client.wrap_oauth = (function cljs_http$client$wrap_oauth(client){
return (function (req){
var temp__5718__auto__ = new cljs.core.Keyword(null,"oauth-token","oauth-token",311415191).cljs$core$IFn$_invoke$arity$1(req);
if(cljs.core.truth_(temp__5718__auto__)){
var oauth_token = temp__5718__auto__;
return client.call(null,cljs.core.assoc_in.call(null,cljs.core.dissoc.call(null,req,new cljs.core.Keyword(null,"oauth-token","oauth-token",311415191)),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"headers","headers",-835030129),"authorization"], null),["Bearer ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(oauth_token)].join('')));
} else {
return client.call(null,req);
}
});
});
/**
* Pipe the response-channel into the request-map's
* custom channel (e.g. to enable transducers)
*/
cljs_http.client.wrap_channel_from_request_map = (function cljs_http$client$wrap_channel_from_request_map(client){
return (function (request){
var temp__5718__auto__ = new cljs.core.Keyword(null,"channel","channel",734187692).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(temp__5718__auto__)){
var custom_channel = temp__5718__auto__;
return cljs.core.async.pipe.call(null,client.call(null,request),custom_channel);
} else {
return client.call(null,request);
}
});
});
/**
* Returns a batteries-included HTTP request function coresponding to the given
* core client. See client/request
*/
cljs_http.client.wrap_request = (function cljs_http$client$wrap_request(request){
return cljs_http.client.wrap_default_headers.call(null,cljs_http.client.wrap_channel_from_request_map.call(null,cljs_http.client.wrap_url.call(null,cljs_http.client.wrap_method.call(null,cljs_http.client.wrap_oauth.call(null,cljs_http.client.wrap_basic_auth.call(null,cljs_http.client.wrap_query_params.call(null,cljs_http.client.wrap_content_type.call(null,cljs_http.client.wrap_json_response.call(null,cljs_http.client.wrap_json_params.call(null,cljs_http.client.wrap_transit_response.call(null,cljs_http.client.wrap_transit_params.call(null,cljs_http.client.wrap_edn_response.call(null,cljs_http.client.wrap_edn_params.call(null,cljs_http.client.wrap_multipart_params.call(null,cljs_http.client.wrap_form_params.call(null,cljs_http.client.wrap_accept.call(null,request)))))))))))))))));
});
/**
* Executes the HTTP request corresponding to the given map and returns the
* response map for corresponding to the resulting HTTP response.
*
* In addition to the standard Ring request keys, the following keys are also
* recognized:
* * :url
* * :method
* * :query-params
*/
cljs_http.client.request = cljs_http.client.wrap_request.call(null,cljs_http.core.request);
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.delete$ = (function cljs_http$client$delete(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25805 = arguments.length;
var i__4731__auto___25806 = (0);
while(true){
if((i__4731__auto___25806 < len__4730__auto___25805)){
args__4736__auto__.push((arguments[i__4731__auto___25806]));
var G__25807 = (i__4731__auto___25806 + (1));
i__4731__auto___25806 = G__25807;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.delete$.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.delete$.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25801){
var vec__25802 = p__25801;
var req = cljs.core.nth.call(null,vec__25802,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"delete","delete",-1768633620),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.delete$.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.delete$.cljs$lang$applyTo = (function (seq25799){
var G__25800 = cljs.core.first.call(null,seq25799);
var seq25799__$1 = cljs.core.next.call(null,seq25799);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25800,seq25799__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.get = (function cljs_http$client$get(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25814 = arguments.length;
var i__4731__auto___25815 = (0);
while(true){
if((i__4731__auto___25815 < len__4730__auto___25814)){
args__4736__auto__.push((arguments[i__4731__auto___25815]));
var G__25816 = (i__4731__auto___25815 + (1));
i__4731__auto___25815 = G__25816;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.get.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.get.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25810){
var vec__25811 = p__25810;
var req = cljs.core.nth.call(null,vec__25811,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"get","get",1683182755),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.get.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.get.cljs$lang$applyTo = (function (seq25808){
var G__25809 = cljs.core.first.call(null,seq25808);
var seq25808__$1 = cljs.core.next.call(null,seq25808);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25809,seq25808__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.head = (function cljs_http$client$head(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25823 = arguments.length;
var i__4731__auto___25824 = (0);
while(true){
if((i__4731__auto___25824 < len__4730__auto___25823)){
args__4736__auto__.push((arguments[i__4731__auto___25824]));
var G__25825 = (i__4731__auto___25824 + (1));
i__4731__auto___25824 = G__25825;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.head.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.head.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25819){
var vec__25820 = p__25819;
var req = cljs.core.nth.call(null,vec__25820,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"head","head",-771383919),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.head.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.head.cljs$lang$applyTo = (function (seq25817){
var G__25818 = cljs.core.first.call(null,seq25817);
var seq25817__$1 = cljs.core.next.call(null,seq25817);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25818,seq25817__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.jsonp = (function cljs_http$client$jsonp(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25832 = arguments.length;
var i__4731__auto___25833 = (0);
while(true){
if((i__4731__auto___25833 < len__4730__auto___25832)){
args__4736__auto__.push((arguments[i__4731__auto___25833]));
var G__25834 = (i__4731__auto___25833 + (1));
i__4731__auto___25833 = G__25834;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.jsonp.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.jsonp.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25828){
var vec__25829 = p__25828;
var req = cljs.core.nth.call(null,vec__25829,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"jsonp","jsonp",226119588),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.jsonp.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.jsonp.cljs$lang$applyTo = (function (seq25826){
var G__25827 = cljs.core.first.call(null,seq25826);
var seq25826__$1 = cljs.core.next.call(null,seq25826);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25827,seq25826__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.move = (function cljs_http$client$move(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25841 = arguments.length;
var i__4731__auto___25842 = (0);
while(true){
if((i__4731__auto___25842 < len__4730__auto___25841)){
args__4736__auto__.push((arguments[i__4731__auto___25842]));
var G__25843 = (i__4731__auto___25842 + (1));
i__4731__auto___25842 = G__25843;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.move.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.move.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25837){
var vec__25838 = p__25837;
var req = cljs.core.nth.call(null,vec__25838,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"move","move",-2110884309),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.move.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.move.cljs$lang$applyTo = (function (seq25835){
var G__25836 = cljs.core.first.call(null,seq25835);
var seq25835__$1 = cljs.core.next.call(null,seq25835);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25836,seq25835__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.options = (function cljs_http$client$options(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25850 = arguments.length;
var i__4731__auto___25851 = (0);
while(true){
if((i__4731__auto___25851 < len__4730__auto___25850)){
args__4736__auto__.push((arguments[i__4731__auto___25851]));
var G__25852 = (i__4731__auto___25851 + (1));
i__4731__auto___25851 = G__25852;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.options.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.options.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25846){
var vec__25847 = p__25846;
var req = cljs.core.nth.call(null,vec__25847,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"options","options",99638489),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.options.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.options.cljs$lang$applyTo = (function (seq25844){
var G__25845 = cljs.core.first.call(null,seq25844);
var seq25844__$1 = cljs.core.next.call(null,seq25844);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25845,seq25844__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.patch = (function cljs_http$client$patch(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25859 = arguments.length;
var i__4731__auto___25860 = (0);
while(true){
if((i__4731__auto___25860 < len__4730__auto___25859)){
args__4736__auto__.push((arguments[i__4731__auto___25860]));
var G__25861 = (i__4731__auto___25860 + (1));
i__4731__auto___25860 = G__25861;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.patch.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.patch.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25855){
var vec__25856 = p__25855;
var req = cljs.core.nth.call(null,vec__25856,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"patch","patch",380775109),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.patch.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.patch.cljs$lang$applyTo = (function (seq25853){
var G__25854 = cljs.core.first.call(null,seq25853);
var seq25853__$1 = cljs.core.next.call(null,seq25853);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25854,seq25853__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.post = (function cljs_http$client$post(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25868 = arguments.length;
var i__4731__auto___25869 = (0);
while(true){
if((i__4731__auto___25869 < len__4730__auto___25868)){
args__4736__auto__.push((arguments[i__4731__auto___25869]));
var G__25870 = (i__4731__auto___25869 + (1));
i__4731__auto___25869 = G__25870;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.post.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.post.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25864){
var vec__25865 = p__25864;
var req = cljs.core.nth.call(null,vec__25865,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"post","post",269697687),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.post.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.post.cljs$lang$applyTo = (function (seq25862){
var G__25863 = cljs.core.first.call(null,seq25862);
var seq25862__$1 = cljs.core.next.call(null,seq25862);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25863,seq25862__$1);
});
/**
* Like #'request, but sets the :method and :url as appropriate.
*/
cljs_http.client.put = (function cljs_http$client$put(var_args){
var args__4736__auto__ = [];
var len__4730__auto___25877 = arguments.length;
var i__4731__auto___25878 = (0);
while(true){
if((i__4731__auto___25878 < len__4730__auto___25877)){
args__4736__auto__.push((arguments[i__4731__auto___25878]));
var G__25879 = (i__4731__auto___25878 + (1));
i__4731__auto___25878 = G__25879;
continue;
} else {
}
break;
}
var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null);
return cljs_http.client.put.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__);
});
cljs_http.client.put.cljs$core$IFn$_invoke$arity$variadic = (function (url,p__25873){
var vec__25874 = p__25873;
var req = cljs.core.nth.call(null,vec__25874,(0),null);
return cljs_http.client.request.call(null,cljs.core.merge.call(null,req,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"method","method",55703592),new cljs.core.Keyword(null,"put","put",1299772570),new cljs.core.Keyword(null,"url","url",276297046),url], null)));
});
cljs_http.client.put.cljs$lang$maxFixedArity = (1);
/** @this {Function} */
cljs_http.client.put.cljs$lang$applyTo = (function (seq25871){
var G__25872 = cljs.core.first.call(null,seq25871);
var seq25871__$1 = cljs.core.next.call(null,seq25871);
var self__4717__auto__ = this;
return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__25872,seq25871__$1);
});
//# sourceMappingURL=client.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,150 @@
(ns cljs-http.core
(:import [goog.net EventType ErrorCode XhrIo]
[goog.net Jsonp])
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs-http.util :as util]
[cljs.core.async :as async]
[clojure.string :as s]))
(def pending-requests (atom {}))
(defn abort!
"Attempt to close the given channel and abort the pending HTTP request
with which it is associated."
[channel]
(when-let [req (@pending-requests channel)]
(swap! pending-requests dissoc channel)
(async/close! channel)
(if (.hasOwnProperty req "abort")
(.abort req)
(.cancel (:jsonp req) (:request req)))))
(defn- aborted? [xhr]
(= (.getLastErrorCode xhr) goog.net.ErrorCode.ABORT))
(defn apply-default-headers!
"Takes an XhrIo object and applies the default-headers to it."
[xhr headers]
(let [formatted-h (zipmap (map util/camelize (keys headers)) (vals headers))]
(dorun
(map (fn [[k v]]
(.set (.-headers xhr) k v))
formatted-h))))
(defn apply-response-type!
"Takes an XhrIo object and sets response-type if not nil."
[xhr response-type]
(.setResponseType xhr
(case response-type
:array-buffer XhrIo.ResponseType.ARRAY_BUFFER
:blob XhrIo.ResponseType.BLOB
:document XhrIo.ResponseType.DOCUMENT
:text XhrIo.ResponseType.TEXT
:default XhrIo.ResponseType.DEFAULT
nil XhrIo.ResponseType.DEFAULT)))
(defn build-xhr
"Builds an XhrIo object from the request parameters."
[{:keys [with-credentials? default-headers response-type] :as request}]
(let [timeout (or (:timeout request) 0)
send-credentials (if (nil? with-credentials?)
true
with-credentials?)]
(doto (XhrIo.)
(apply-default-headers! default-headers)
(apply-response-type! response-type)
(.setTimeoutInterval timeout)
(.setWithCredentials send-credentials))))
;; goog.net.ErrorCode constants to CLJS keywords
(def error-kw
{0 :no-error
1 :access-denied
2 :file-not-found
3 :ff-silent-error
4 :custom-error
5 :exception
6 :http-error
7 :abort
8 :timeout
9 :offline})
(defn xhr
"Execute the HTTP request corresponding to the given Ring request
map and return a core.async channel."
[{:keys [request-method headers body with-credentials? cancel progress] :as request}]
(let [channel (async/chan)
request-url (util/build-url request)
method (name (or request-method :get))
headers (util/build-headers headers)
xhr (build-xhr request)]
(swap! pending-requests assoc channel xhr)
(.listen xhr EventType.COMPLETE
(fn [evt]
(let [target (.-target evt)
response {:status (.getStatus target)
:success (.isSuccess target)
:body (.getResponse target)
:headers (util/parse-headers (.getAllResponseHeaders target))
:trace-redirects [request-url (.getLastUri target)]
:error-code (error-kw (.getLastErrorCode target))
:error-text (.getLastError target)}]
(if-not (aborted? xhr)
(async/put! channel response))
(swap! pending-requests dissoc channel)
(if cancel (async/close! cancel))
(async/close! channel))))
(when progress
(let [listener (fn [direction evt]
(async/put! progress (merge {:direction direction :loaded (.-loaded evt)}
(if (.-lengthComputable evt) {:total (.-total evt)}))))]
(doto xhr
(.setProgressEventsEnabled true)
(.listen EventType.UPLOAD_PROGRESS (partial listener :upload))
(.listen EventType.DOWNLOAD_PROGRESS (partial listener :download)))))
(.send xhr request-url method body headers)
(if cancel
(go
(let [v (async/<! cancel)]
(if (not (.isComplete xhr))
(.abort xhr)))))
channel))
(defn jsonp
"Execute the JSONP request corresponding to the given Ring request
map and return a core.async channel."
[{:keys [timeout callback-name cancel keywordize-keys?]
:or {keywordize-keys? true}
:as request}]
(let [channel (async/chan)
jsonp (Jsonp. (util/build-url request) callback-name)]
(.setRequestTimeout jsonp timeout)
(let [req (.send jsonp nil
(fn success-callback [data]
(let [response {:status 200
:success true
:body (js->clj data :keywordize-keys keywordize-keys?)}]
(async/put! channel response)
(swap! pending-requests dissoc channel)
(if cancel (async/close! cancel))
(async/close! channel)))
(fn error-callback []
(swap! pending-requests dissoc channel)
(if cancel (async/close! cancel))
(async/close! channel)))]
(swap! pending-requests assoc channel {:jsonp jsonp :request req})
(if cancel
(go
(let [v (async/<! cancel)]
(.cancel jsonp req)))))
channel))
(defn request
"Execute the HTTP request corresponding to the given Ring request
map and return a core.async channel."
[{:keys [request-method] :as request}]
(if (= request-method :jsonp)
(jsonp request)
(xhr request)))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,480 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('cljs_http.core');
goog.require('cljs.core');
goog.require('goog.net.EventType');
goog.require('goog.net.ErrorCode');
goog.require('goog.net.XhrIo');
goog.require('goog.net.Jsonp');
goog.require('cljs_http.util');
goog.require('cljs.core.async');
goog.require('clojure.string');
cljs_http.core.pending_requests = cljs.core.atom.call(null,cljs.core.PersistentArrayMap.EMPTY);
/**
* Attempt to close the given channel and abort the pending HTTP request
* with which it is associated.
*/
cljs_http.core.abort_BANG_ = (function cljs_http$core$abort_BANG_(channel){
var temp__5720__auto__ = cljs.core.deref.call(null,cljs_http.core.pending_requests).call(null,channel);
if(cljs.core.truth_(temp__5720__auto__)){
var req = temp__5720__auto__;
cljs.core.swap_BANG_.call(null,cljs_http.core.pending_requests,cljs.core.dissoc,channel);
cljs.core.async.close_BANG_.call(null,channel);
if(cljs.core.truth_(req.hasOwnProperty("abort"))){
return req.abort();
} else {
return new cljs.core.Keyword(null,"jsonp","jsonp",226119588).cljs$core$IFn$_invoke$arity$1(req).cancel(new cljs.core.Keyword(null,"request","request",1772954723).cljs$core$IFn$_invoke$arity$1(req));
}
} else {
return null;
}
});
cljs_http.core.aborted_QMARK_ = (function cljs_http$core$aborted_QMARK_(xhr){
return cljs.core._EQ_.call(null,xhr.getLastErrorCode(),goog.net.ErrorCode.ABORT);
});
/**
* Takes an XhrIo object and applies the default-headers to it.
*/
cljs_http.core.apply_default_headers_BANG_ = (function cljs_http$core$apply_default_headers_BANG_(xhr,headers){
var formatted_h = cljs.core.zipmap.call(null,cljs.core.map.call(null,cljs_http.util.camelize,cljs.core.keys.call(null,headers)),cljs.core.vals.call(null,headers));
return cljs.core.dorun.call(null,cljs.core.map.call(null,((function (formatted_h){
return (function (p__25585){
var vec__25586 = p__25585;
var k = cljs.core.nth.call(null,vec__25586,(0),null);
var v = cljs.core.nth.call(null,vec__25586,(1),null);
return xhr.headers.set(k,v);
});})(formatted_h))
,formatted_h));
});
/**
* Takes an XhrIo object and sets response-type if not nil.
*/
cljs_http.core.apply_response_type_BANG_ = (function cljs_http$core$apply_response_type_BANG_(xhr,response_type){
return xhr.setResponseType((function (){var G__25589 = response_type;
if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"array-buffer","array-buffer",519008380),G__25589)){
return goog.net.XhrIo.ResponseType.ARRAY_BUFFER;
} else {
if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"blob","blob",1636965233),G__25589)){
return goog.net.XhrIo.ResponseType.BLOB;
} else {
if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"document","document",-1329188687),G__25589)){
return goog.net.XhrIo.ResponseType.DOCUMENT;
} else {
if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"text","text",-1790561697),G__25589)){
return goog.net.XhrIo.ResponseType.TEXT;
} else {
if(cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"default","default",-1987822328),G__25589)){
return goog.net.XhrIo.ResponseType.DEFAULT;
} else {
if(cljs.core._EQ_.call(null,null,G__25589)){
return goog.net.XhrIo.ResponseType.DEFAULT;
} else {
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__25589)].join('')));
}
}
}
}
}
}
})());
});
/**
* Builds an XhrIo object from the request parameters.
*/
cljs_http.core.build_xhr = (function cljs_http$core$build_xhr(p__25590){
var map__25591 = p__25590;
var map__25591__$1 = (((((!((map__25591 == null))))?(((((map__25591.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25591.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25591):map__25591);
var request = map__25591__$1;
var with_credentials_QMARK_ = cljs.core.get.call(null,map__25591__$1,new cljs.core.Keyword(null,"with-credentials?","with-credentials?",-1773202222));
var default_headers = cljs.core.get.call(null,map__25591__$1,new cljs.core.Keyword(null,"default-headers","default-headers",-43146094));
var response_type = cljs.core.get.call(null,map__25591__$1,new cljs.core.Keyword(null,"response-type","response-type",-1493770458));
var timeout = (function (){var or__4131__auto__ = new cljs.core.Keyword(null,"timeout","timeout",-318625318).cljs$core$IFn$_invoke$arity$1(request);
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return (0);
}
})();
var send_credentials = (((with_credentials_QMARK_ == null))?true:with_credentials_QMARK_);
var G__25593 = (new goog.net.XhrIo());
cljs_http.core.apply_default_headers_BANG_.call(null,G__25593,default_headers);
cljs_http.core.apply_response_type_BANG_.call(null,G__25593,response_type);
G__25593.setTimeoutInterval(timeout);
G__25593.setWithCredentials(send_credentials);
return G__25593;
});
cljs_http.core.error_kw = cljs.core.PersistentHashMap.fromArrays([(0),(7),(1),(4),(6),(3),(2),(9),(5),(8)],[new cljs.core.Keyword(null,"no-error","no-error",1984610064),new cljs.core.Keyword(null,"abort","abort",521193198),new cljs.core.Keyword(null,"access-denied","access-denied",959449406),new cljs.core.Keyword(null,"custom-error","custom-error",-1565161123),new cljs.core.Keyword(null,"http-error","http-error",-1040049553),new cljs.core.Keyword(null,"ff-silent-error","ff-silent-error",189390514),new cljs.core.Keyword(null,"file-not-found","file-not-found",-65398940),new cljs.core.Keyword(null,"offline","offline",-107631935),new cljs.core.Keyword(null,"exception","exception",-335277064),new cljs.core.Keyword(null,"timeout","timeout",-318625318)]);
/**
* Execute the HTTP request corresponding to the given Ring request
* map and return a core.async channel.
*/
cljs_http.core.xhr = (function cljs_http$core$xhr(p__25594){
var map__25595 = p__25594;
var map__25595__$1 = (((((!((map__25595 == null))))?(((((map__25595.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25595.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25595):map__25595);
var request = map__25595__$1;
var request_method = cljs.core.get.call(null,map__25595__$1,new cljs.core.Keyword(null,"request-method","request-method",1764796830));
var headers = cljs.core.get.call(null,map__25595__$1,new cljs.core.Keyword(null,"headers","headers",-835030129));
var body = cljs.core.get.call(null,map__25595__$1,new cljs.core.Keyword(null,"body","body",-2049205669));
var with_credentials_QMARK_ = cljs.core.get.call(null,map__25595__$1,new cljs.core.Keyword(null,"with-credentials?","with-credentials?",-1773202222));
var cancel = cljs.core.get.call(null,map__25595__$1,new cljs.core.Keyword(null,"cancel","cancel",-1964088360));
var progress = cljs.core.get.call(null,map__25595__$1,new cljs.core.Keyword(null,"progress","progress",244323547));
var channel = cljs.core.async.chan.call(null);
var request_url = cljs_http.util.build_url.call(null,request);
var method = cljs.core.name.call(null,(function (){var or__4131__auto__ = request_method;
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return new cljs.core.Keyword(null,"get","get",1683182755);
}
})());
var headers__$1 = cljs_http.util.build_headers.call(null,headers);
var xhr = cljs_http.core.build_xhr.call(null,request);
cljs.core.swap_BANG_.call(null,cljs_http.core.pending_requests,cljs.core.assoc,channel,xhr);
xhr.listen(goog.net.EventType.COMPLETE,((function (channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress){
return (function (evt){
var target = evt.target;
var response = new cljs.core.PersistentArrayMap(null, 7, [new cljs.core.Keyword(null,"status","status",-1997798413),target.getStatus(),new cljs.core.Keyword(null,"success","success",1890645906),target.isSuccess(),new cljs.core.Keyword(null,"body","body",-2049205669),target.getResponse(),new cljs.core.Keyword(null,"headers","headers",-835030129),cljs_http.util.parse_headers.call(null,target.getAllResponseHeaders()),new cljs.core.Keyword(null,"trace-redirects","trace-redirects",-1149427907),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [request_url,target.getLastUri()], null),new cljs.core.Keyword(null,"error-code","error-code",180497232),cljs_http.core.error_kw.call(null,target.getLastErrorCode()),new cljs.core.Keyword(null,"error-text","error-text",2021893718),target.getLastError()], null);
if((!(cljs_http.core.aborted_QMARK_.call(null,xhr)))){
cljs.core.async.put_BANG_.call(null,channel,response);
} else {
}
cljs.core.swap_BANG_.call(null,cljs_http.core.pending_requests,cljs.core.dissoc,channel);
if(cljs.core.truth_(cancel)){
cljs.core.async.close_BANG_.call(null,cancel);
} else {
}
return cljs.core.async.close_BANG_.call(null,channel);
});})(channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress))
);
if(cljs.core.truth_(progress)){
var listener_25619 = ((function (channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress){
return (function (direction,evt){
return cljs.core.async.put_BANG_.call(null,progress,cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"direction","direction",-633359395),direction,new cljs.core.Keyword(null,"loaded","loaded",-1246482293),evt.loaded], null),(cljs.core.truth_(evt.lengthComputable)?new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"total","total",1916810418),evt.total], null):null)));
});})(channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress))
;
var G__25597_25620 = xhr;
G__25597_25620.setProgressEventsEnabled(true);
G__25597_25620.listen(goog.net.EventType.UPLOAD_PROGRESS,cljs.core.partial.call(null,listener_25619,new cljs.core.Keyword(null,"upload","upload",-255769218)));
G__25597_25620.listen(goog.net.EventType.DOWNLOAD_PROGRESS,cljs.core.partial.call(null,listener_25619,new cljs.core.Keyword(null,"download","download",-300081668)));
} else {
}
xhr.send(request_url,method,body,headers__$1);
if(cljs.core.truth_(cancel)){
var c__23644__auto___25621 = cljs.core.async.chan.call(null,(1));
cljs.core.async.impl.dispatch.run.call(null,((function (c__23644__auto___25621,channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress){
return (function (){
var f__23645__auto__ = (function (){var switch__23549__auto__ = ((function (c__23644__auto___25621,channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress){
return (function (state_25608){
var state_val_25609 = (state_25608[(1)]);
if((state_val_25609 === (1))){
var state_25608__$1 = state_25608;
return cljs.core.async.impl.ioc_helpers.take_BANG_.call(null,state_25608__$1,(2),cancel);
} else {
if((state_val_25609 === (2))){
var inst_25599 = (state_25608[(2)]);
var inst_25600 = xhr.isComplete();
var inst_25601 = cljs.core.not.call(null,inst_25600);
var state_25608__$1 = (function (){var statearr_25610 = state_25608;
(statearr_25610[(7)] = inst_25599);
return statearr_25610;
})();
if(inst_25601){
var statearr_25611_25622 = state_25608__$1;
(statearr_25611_25622[(1)] = (3));
} else {
var statearr_25612_25623 = state_25608__$1;
(statearr_25612_25623[(1)] = (4));
}
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
if((state_val_25609 === (3))){
var inst_25603 = xhr.abort();
var state_25608__$1 = state_25608;
var statearr_25613_25624 = state_25608__$1;
(statearr_25613_25624[(2)] = inst_25603);
(statearr_25613_25624[(1)] = (5));
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
if((state_val_25609 === (4))){
var state_25608__$1 = state_25608;
var statearr_25614_25625 = state_25608__$1;
(statearr_25614_25625[(2)] = null);
(statearr_25614_25625[(1)] = (5));
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
if((state_val_25609 === (5))){
var inst_25606 = (state_25608[(2)]);
var state_25608__$1 = state_25608;
return cljs.core.async.impl.ioc_helpers.return_chan.call(null,state_25608__$1,inst_25606);
} else {
return null;
}
}
}
}
}
});})(c__23644__auto___25621,channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress))
;
return ((function (switch__23549__auto__,c__23644__auto___25621,channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress){
return (function() {
var cljs_http$core$xhr_$_state_machine__23550__auto__ = null;
var cljs_http$core$xhr_$_state_machine__23550__auto____0 = (function (){
var statearr_25615 = [null,null,null,null,null,null,null,null];
(statearr_25615[(0)] = cljs_http$core$xhr_$_state_machine__23550__auto__);
(statearr_25615[(1)] = (1));
return statearr_25615;
});
var cljs_http$core$xhr_$_state_machine__23550__auto____1 = (function (state_25608){
while(true){
var ret_value__23551__auto__ = (function (){try{while(true){
var result__23552__auto__ = switch__23549__auto__.call(null,state_25608);
if(cljs.core.keyword_identical_QMARK_.call(null,result__23552__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
continue;
} else {
return result__23552__auto__;
}
break;
}
}catch (e25616){if((e25616 instanceof Object)){
var ex__23553__auto__ = e25616;
var statearr_25617_25626 = state_25608;
(statearr_25617_25626[(5)] = ex__23553__auto__);
cljs.core.async.impl.ioc_helpers.process_exception.call(null,state_25608);
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
throw e25616;
}
}})();
if(cljs.core.keyword_identical_QMARK_.call(null,ret_value__23551__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
var G__25627 = state_25608;
state_25608 = G__25627;
continue;
} else {
return ret_value__23551__auto__;
}
break;
}
});
cljs_http$core$xhr_$_state_machine__23550__auto__ = function(state_25608){
switch(arguments.length){
case 0:
return cljs_http$core$xhr_$_state_machine__23550__auto____0.call(this);
case 1:
return cljs_http$core$xhr_$_state_machine__23550__auto____1.call(this,state_25608);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
cljs_http$core$xhr_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$0 = cljs_http$core$xhr_$_state_machine__23550__auto____0;
cljs_http$core$xhr_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$1 = cljs_http$core$xhr_$_state_machine__23550__auto____1;
return cljs_http$core$xhr_$_state_machine__23550__auto__;
})()
;})(switch__23549__auto__,c__23644__auto___25621,channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress))
})();
var state__23646__auto__ = (function (){var statearr_25618 = f__23645__auto__.call(null);
(statearr_25618[(6)] = c__23644__auto___25621);
return statearr_25618;
})();
return cljs.core.async.impl.ioc_helpers.run_state_machine_wrapped.call(null,state__23646__auto__);
});})(c__23644__auto___25621,channel,request_url,method,headers__$1,xhr,map__25595,map__25595__$1,request,request_method,headers,body,with_credentials_QMARK_,cancel,progress))
);
} else {
}
return channel;
});
/**
* Execute the JSONP request corresponding to the given Ring request
* map and return a core.async channel.
*/
cljs_http.core.jsonp = (function cljs_http$core$jsonp(p__25628){
var map__25629 = p__25628;
var map__25629__$1 = (((((!((map__25629 == null))))?(((((map__25629.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25629.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25629):map__25629);
var request = map__25629__$1;
var timeout = cljs.core.get.call(null,map__25629__$1,new cljs.core.Keyword(null,"timeout","timeout",-318625318));
var callback_name = cljs.core.get.call(null,map__25629__$1,new cljs.core.Keyword(null,"callback-name","callback-name",336964714));
var cancel = cljs.core.get.call(null,map__25629__$1,new cljs.core.Keyword(null,"cancel","cancel",-1964088360));
var keywordize_keys_QMARK_ = cljs.core.get.call(null,map__25629__$1,new cljs.core.Keyword(null,"keywordize-keys?","keywordize-keys?",-254545987),true);
var channel = cljs.core.async.chan.call(null);
var jsonp = (new goog.net.Jsonp(cljs_http.util.build_url.call(null,request),callback_name));
jsonp.setRequestTimeout(timeout);
var req_25642 = jsonp.send(null,((function (channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_){
return (function cljs_http$core$jsonp_$_success_callback(data){
var response = new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"status","status",-1997798413),(200),new cljs.core.Keyword(null,"success","success",1890645906),true,new cljs.core.Keyword(null,"body","body",-2049205669),cljs.core.js__GT_clj.call(null,data,new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",1310784252),keywordize_keys_QMARK_)], null);
cljs.core.async.put_BANG_.call(null,channel,response);
cljs.core.swap_BANG_.call(null,cljs_http.core.pending_requests,cljs.core.dissoc,channel);
if(cljs.core.truth_(cancel)){
cljs.core.async.close_BANG_.call(null,cancel);
} else {
}
return cljs.core.async.close_BANG_.call(null,channel);
});})(channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_))
,((function (channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_){
return (function cljs_http$core$jsonp_$_error_callback(){
cljs.core.swap_BANG_.call(null,cljs_http.core.pending_requests,cljs.core.dissoc,channel);
if(cljs.core.truth_(cancel)){
cljs.core.async.close_BANG_.call(null,cancel);
} else {
}
return cljs.core.async.close_BANG_.call(null,channel);
});})(channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_))
);
cljs.core.swap_BANG_.call(null,cljs_http.core.pending_requests,cljs.core.assoc,channel,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"jsonp","jsonp",226119588),jsonp,new cljs.core.Keyword(null,"request","request",1772954723),req_25642], null));
if(cljs.core.truth_(cancel)){
var c__23644__auto___25643 = cljs.core.async.chan.call(null,(1));
cljs.core.async.impl.dispatch.run.call(null,((function (c__23644__auto___25643,req_25642,channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_){
return (function (){
var f__23645__auto__ = (function (){var switch__23549__auto__ = ((function (c__23644__auto___25643,req_25642,channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_){
return (function (state_25635){
var state_val_25636 = (state_25635[(1)]);
if((state_val_25636 === (1))){
var state_25635__$1 = state_25635;
return cljs.core.async.impl.ioc_helpers.take_BANG_.call(null,state_25635__$1,(2),cancel);
} else {
if((state_val_25636 === (2))){
var inst_25632 = (state_25635[(2)]);
var inst_25633 = jsonp.cancel(req_25642);
var state_25635__$1 = (function (){var statearr_25637 = state_25635;
(statearr_25637[(7)] = inst_25632);
return statearr_25637;
})();
return cljs.core.async.impl.ioc_helpers.return_chan.call(null,state_25635__$1,inst_25633);
} else {
return null;
}
}
});})(c__23644__auto___25643,req_25642,channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_))
;
return ((function (switch__23549__auto__,c__23644__auto___25643,req_25642,channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_){
return (function() {
var cljs_http$core$jsonp_$_state_machine__23550__auto__ = null;
var cljs_http$core$jsonp_$_state_machine__23550__auto____0 = (function (){
var statearr_25638 = [null,null,null,null,null,null,null,null];
(statearr_25638[(0)] = cljs_http$core$jsonp_$_state_machine__23550__auto__);
(statearr_25638[(1)] = (1));
return statearr_25638;
});
var cljs_http$core$jsonp_$_state_machine__23550__auto____1 = (function (state_25635){
while(true){
var ret_value__23551__auto__ = (function (){try{while(true){
var result__23552__auto__ = switch__23549__auto__.call(null,state_25635);
if(cljs.core.keyword_identical_QMARK_.call(null,result__23552__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
continue;
} else {
return result__23552__auto__;
}
break;
}
}catch (e25639){if((e25639 instanceof Object)){
var ex__23553__auto__ = e25639;
var statearr_25640_25644 = state_25635;
(statearr_25640_25644[(5)] = ex__23553__auto__);
cljs.core.async.impl.ioc_helpers.process_exception.call(null,state_25635);
return new cljs.core.Keyword(null,"recur","recur",-437573268);
} else {
throw e25639;
}
}})();
if(cljs.core.keyword_identical_QMARK_.call(null,ret_value__23551__auto__,new cljs.core.Keyword(null,"recur","recur",-437573268))){
var G__25645 = state_25635;
state_25635 = G__25645;
continue;
} else {
return ret_value__23551__auto__;
}
break;
}
});
cljs_http$core$jsonp_$_state_machine__23550__auto__ = function(state_25635){
switch(arguments.length){
case 0:
return cljs_http$core$jsonp_$_state_machine__23550__auto____0.call(this);
case 1:
return cljs_http$core$jsonp_$_state_machine__23550__auto____1.call(this,state_25635);
}
throw(new Error('Invalid arity: ' + arguments.length));
};
cljs_http$core$jsonp_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$0 = cljs_http$core$jsonp_$_state_machine__23550__auto____0;
cljs_http$core$jsonp_$_state_machine__23550__auto__.cljs$core$IFn$_invoke$arity$1 = cljs_http$core$jsonp_$_state_machine__23550__auto____1;
return cljs_http$core$jsonp_$_state_machine__23550__auto__;
})()
;})(switch__23549__auto__,c__23644__auto___25643,req_25642,channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_))
})();
var state__23646__auto__ = (function (){var statearr_25641 = f__23645__auto__.call(null);
(statearr_25641[(6)] = c__23644__auto___25643);
return statearr_25641;
})();
return cljs.core.async.impl.ioc_helpers.run_state_machine_wrapped.call(null,state__23646__auto__);
});})(c__23644__auto___25643,req_25642,channel,jsonp,map__25629,map__25629__$1,request,timeout,callback_name,cancel,keywordize_keys_QMARK_))
);
} else {
}
return channel;
});
/**
* Execute the HTTP request corresponding to the given Ring request
* map and return a core.async channel.
*/
cljs_http.core.request = (function cljs_http$core$request(p__25646){
var map__25647 = p__25646;
var map__25647__$1 = (((((!((map__25647 == null))))?(((((map__25647.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__25647.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__25647):map__25647);
var request = map__25647__$1;
var request_method = cljs.core.get.call(null,map__25647__$1,new cljs.core.Keyword(null,"request-method","request-method",1764796830));
if(cljs.core._EQ_.call(null,request_method,new cljs.core.Keyword(null,"jsonp","jsonp",226119588))){
return cljs_http.core.jsonp.call(null,request);
} else {
return cljs_http.core.xhr.call(null,request);
}
});
//# sourceMappingURL=core.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,77 @@
(ns cljs-http.util
(:refer-clojure :exclude [uri?])
(:import goog.Uri)
(:require [clojure.string :refer [blank? capitalize join split lower-case]]
[cognitect.transit :as t]
[goog.userAgent :as agent]
[no.en.core :refer [base64-encode]]))
(defn basic-auth
"Returns the value of the HTTP basic authentication header for
`credentials`."
[credentials]
(if credentials
(let [[username password]
(if (map? credentials)
(map credentials [:username :password])
credentials)]
(str "Basic " (base64-encode (str username ":" password))))))
(defn build-url
"Build the url from the request map."
[{:keys [scheme server-name server-port uri query-string]}]
(str (doto (Uri.)
(.setScheme (name (or scheme :http)))
(.setDomain server-name)
(.setPort server-port)
(.setPath uri)
(.setQuery query-string true))))
(defn camelize
"Returns dash separated string `s` in camel case."
[s]
(->> (split (str s) #"-")
(map capitalize)
(join "-")))
(defn build-headers
"Build the headers from the map."
[m] (clj->js (zipmap (map camelize (keys m)) (vals m))))
(defn user-agent
"Returns the user agent."
[] (agent/getUserAgentString))
(defn android?
"Returns true if the user agent is an Android client."
[] (re-matches #"(?i).*android.*" (user-agent)))
(defn transit-decode
"Transit decode an object from `s`."
[s type opts]
(let [rdr (t/reader type opts)]
(t/read rdr s)))
(defn transit-encode
"Transit encode `x` into a String."
[x type opts]
(let [wrtr (t/writer type opts)]
(t/write wrtr x)))
(defn json-decode
"JSON decode an object from `s`."
[s]
(let [v (if-not (clojure.string/blank? s) (js/JSON.parse s))]
(when (some? v)
(js->clj v :keywordize-keys true))))
(defn json-encode
"JSON encode `x` into a String."
[x] (js/JSON.stringify (clj->js x)))
(defn parse-headers [headers]
(reduce
#(let [[k v] (split %2 #":\s+")]
(if (or (blank? k) (blank? v))
%1 (assoc %1 (lower-case k) v)))
{} (split (or headers "") #"(\n)|(\r)|(\r\n)|(\n\r)")))

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,128 @@
// Compiled by ClojureScript 1.10.520 {}
goog.provide('cljs_http.util');
goog.require('cljs.core');
goog.require('goog.Uri');
goog.require('clojure.string');
goog.require('cognitect.transit');
goog.require('goog.userAgent');
goog.require('no.en.core');
/**
* Returns the value of the HTTP basic authentication header for
* `credentials`.
*/
cljs_http.util.basic_auth = (function cljs_http$util$basic_auth(credentials){
if(cljs.core.truth_(credentials)){
var vec__22294 = ((cljs.core.map_QMARK_.call(null,credentials))?cljs.core.map.call(null,credentials,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"username","username",1605666410),new cljs.core.Keyword(null,"password","password",417022471)], null)):credentials);
var username = cljs.core.nth.call(null,vec__22294,(0),null);
var password = cljs.core.nth.call(null,vec__22294,(1),null);
return ["Basic ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(no.en.core.base64_encode.call(null,[cljs.core.str.cljs$core$IFn$_invoke$arity$1(username),":",cljs.core.str.cljs$core$IFn$_invoke$arity$1(password)].join('')))].join('');
} else {
return null;
}
});
/**
* Build the url from the request map.
*/
cljs_http.util.build_url = (function cljs_http$util$build_url(p__22297){
var map__22298 = p__22297;
var map__22298__$1 = (((((!((map__22298 == null))))?(((((map__22298.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__22298.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__22298):map__22298);
var scheme = cljs.core.get.call(null,map__22298__$1,new cljs.core.Keyword(null,"scheme","scheme",90199613));
var server_name = cljs.core.get.call(null,map__22298__$1,new cljs.core.Keyword(null,"server-name","server-name",-1012104295));
var server_port = cljs.core.get.call(null,map__22298__$1,new cljs.core.Keyword(null,"server-port","server-port",663745648));
var uri = cljs.core.get.call(null,map__22298__$1,new cljs.core.Keyword(null,"uri","uri",-774711847));
var query_string = cljs.core.get.call(null,map__22298__$1,new cljs.core.Keyword(null,"query-string","query-string",-1018845061));
return cljs.core.str.cljs$core$IFn$_invoke$arity$1((function (){var G__22301 = (new goog.Uri());
G__22301.setScheme(cljs.core.name.call(null,(function (){var or__4131__auto__ = scheme;
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return new cljs.core.Keyword(null,"http","http",382524695);
}
})()));
G__22301.setDomain(server_name);
G__22301.setPort(server_port);
G__22301.setPath(uri);
G__22301.setQuery(query_string,true);
return G__22301;
})());
});
/**
* Returns dash separated string `s` in camel case.
*/
cljs_http.util.camelize = (function cljs_http$util$camelize(s){
return clojure.string.join.call(null,"-",cljs.core.map.call(null,clojure.string.capitalize,clojure.string.split.call(null,cljs.core.str.cljs$core$IFn$_invoke$arity$1(s),/-/)));
});
/**
* Build the headers from the map.
*/
cljs_http.util.build_headers = (function cljs_http$util$build_headers(m){
return cljs.core.clj__GT_js.call(null,cljs.core.zipmap.call(null,cljs.core.map.call(null,cljs_http.util.camelize,cljs.core.keys.call(null,m)),cljs.core.vals.call(null,m)));
});
/**
* Returns the user agent.
*/
cljs_http.util.user_agent = (function cljs_http$util$user_agent(){
return goog.userAgent.getUserAgentString();
});
/**
* Returns true if the user agent is an Android client.
*/
cljs_http.util.android_QMARK_ = (function cljs_http$util$android_QMARK_(){
return cljs.core.re_matches.call(null,/.*android.*/i,cljs_http.util.user_agent.call(null));
});
/**
* Transit decode an object from `s`.
*/
cljs_http.util.transit_decode = (function cljs_http$util$transit_decode(s,type,opts){
var rdr = cognitect.transit.reader.call(null,type,opts);
return cognitect.transit.read.call(null,rdr,s);
});
/**
* Transit encode `x` into a String.
*/
cljs_http.util.transit_encode = (function cljs_http$util$transit_encode(x,type,opts){
var wrtr = cognitect.transit.writer.call(null,type,opts);
return cognitect.transit.write.call(null,wrtr,x);
});
/**
* JSON decode an object from `s`.
*/
cljs_http.util.json_decode = (function cljs_http$util$json_decode(s){
var v = (((!(clojure.string.blank_QMARK_.call(null,s))))?JSON.parse(s):null);
if((!((v == null)))){
return cljs.core.js__GT_clj.call(null,v,new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",1310784252),true);
} else {
return null;
}
});
/**
* JSON encode `x` into a String.
*/
cljs_http.util.json_encode = (function cljs_http$util$json_encode(x){
return JSON.stringify(cljs.core.clj__GT_js.call(null,x));
});
cljs_http.util.parse_headers = (function cljs_http$util$parse_headers(headers){
return cljs.core.reduce.call(null,(function (p1__22303_SHARP_,p2__22302_SHARP_){
var vec__22304 = clojure.string.split.call(null,p2__22302_SHARP_,/:\s+/);
var k = cljs.core.nth.call(null,vec__22304,(0),null);
var v = cljs.core.nth.call(null,vec__22304,(1),null);
if(((clojure.string.blank_QMARK_.call(null,k)) || (clojure.string.blank_QMARK_.call(null,v)))){
return p1__22303_SHARP_;
} else {
return cljs.core.assoc.call(null,p1__22303_SHARP_,clojure.string.lower_case.call(null,k),v);
}
}),cljs.core.PersistentArrayMap.EMPTY,clojure.string.split.call(null,(function (){var or__4131__auto__ = headers;
if(cljs.core.truth_(or__4131__auto__)){
return or__4131__auto__;
} else {
return "";
}
})(),/(\n)|(\r)|(\r\n)|(\n\r)/));
});
//# sourceMappingURL=util.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"\/home\/simon\/workspace\/geocsv-lite\/target\/cljsbuild-compiler-1\/cljs_http\/util.js","sources":["util.cljs"],"lineCount":128,"mappings":";AAAA;;;;;;;AAQA;;;;4BAAA,5BAAMA,gEAGHC;AAHH,AAIE,oBAAIA;AACF,IAAAC,aACM,EAAI,AAACI,+BAAKL,cACR,oCAAA,mFAAA,6DAAA,pLAACM,wBAAIN,iOACLA;eAHR,AAAAE,wBAAAD,WAAA,IAAA,lDAAOE;eAAP,AAAAD,wBAAAD,WAAA,IAAA,lDAAgBG;AAAhB,AAIE,QAAA,qDAAc,AAACG,mCAAc,uDAAA,VAAKJ,0DAAaC;;AALnD;;;AAOF;;;2BAAA,mCAAAI,9DAAMM;AAAN,AAAA,IAAAL,aAAAD;IAAAC,iBAAA,EAAA,EAAA,GAAA,CAAAA,cAAA,SAAA,EAAA,EAAA,CAAA,AAAAA,iDAAA,WAAA,CAAAC,gCAAA,AAAAD,+BAAA,KAAA,OAAA,QAAA,AAAAE,0BAAAC,mBAAAH,YAAAA;aAAA,AAAAI,wBAAAJ,eAAA,hDAEWM;kBAFX,AAAAF,wBAAAJ,eAAA,rDAEkBO;kBAFlB,AAAAH,wBAAAJ,eAAA,rDAE8BQ;UAF9B,AAAAJ,wBAAAJ,eAAA,7CAE0CS;mBAF1C,AAAAL,wBAAAJ,eAAA,tDAE8CU;AAF9C,AAGE,mDAAK,iBAAAC,WAAM,KAAAC;AAAN,AAAA,AAAAD,mBACc,AAACE,yBAAK,iBAAAC,mBAAIR;AAAJ,AAAA,oBAAAQ;AAAAA;;AAAA;;;;AADpB,AAAAH,mBAEcJ;;AAFd,AAAAI,iBAGYH;;AAHZ,AAAAG,iBAIYF;;AAJZ,AAAAE,+BAAA,bAKaD;;AALbC;;;AAOP;;;0BAAA,1BAAMI,4DAEHC;AAFH,2FAGO,8EAAA,9EAACC,+BAAM,4CAAKD,7HACZ,AAACnB,wBAAIqB,jEACL,qCAAA,9BAACC;;AAER;;;+BAAA,\/BAAMC,sEAEHC;AAFH,AAEM,OAACC,+BAAQ,AAACC,2BAAO,AAAC1B,wBAAIkB,wBAAS,AAACS,yBAAKH,IAAI,AAACI,yBAAKJ;;AAErD;;;4BAAA,5BAAMK;AAAN,AAEK,OAACC;;AAEN;;;gCAAA,hCAAMC;AAAN,AAEK,sCAAA,\/BAACC,8CAA8B,AAACH;;AAErC;;;gCAAA,hCAAMI,wEAEHd,EAAEe,KAAKC;AAFV,AAGE,IAAMC,MAAI,AAACC,mCAASH,KAAKC;AAAzB,AACE,OAACG,iCAAOF,IAAIjB;;AAEhB;;;gCAAA,hCAAMoB,wEAEHC,EAAEN,KAAKC;AAFV,AAGE,IAAMM,OAAK,AAACC,mCAASR,KAAKC;AAA1B,AACE,OAACQ,kCAAQF,KAAKD;;AAElB;;;6BAAA,7BAAMI,kEAEHzB;AAFH,AAGE,IAAM0B,IAAE,EAAA,6DAAA,1DAAQ,AAACC,sCAAsB3B,MAAG,AAAC4B,WAAc5B;AAAzD,AACE,GAAM,GAAA,MAAA,LAAO0B;AAAb,AACE,wCAAA,2EAAA,5GAACG,+BAAQH;;AADX;;;AAGJ;;;6BAAA,7BAAMI,kEAEHT;AAFH,AAEM,OAACU,eAAkB,AAACzB,+BAAQe;;AAElC,+BAAA,\/BAAMW,sEAAeC;AAArB,AACE,kCAAA,WAAAC,iBAAAC,vDAACC;AAAD,AACE,IAAAC,aAAY,+BAAAF,iBAAA,hDAAClC;QAAb,AAAAxB,wBAAA4D,WAAA,IAAA,3CAAOC;QAAP,AAAA7D,wBAAA4D,WAAA,IAAA,3CAASX;AAAT,AACE,GAAI,EAAI,AAACC,sCAAOW,QAAG,AAACX,sCAAOD;AAA3BQ;;AACK,iCAAAA,1BAACK,2CAAS,AAACC,oCAAWF,GAAGZ;;GAHlC,mCAII,AAACzB,+BAAM,iBAAAH,mBAAImC;AAAJ,AAAA,oBAAAnC;AAAAA;;AAAA;;KAAP","names":["cljs-http.util\/basic-auth","credentials","vec__22294","cljs.core\/nth","username","password","cljs.core\/map?","cljs.core\/map","no.en.core\/base64-encode","p__22297","map__22298","cljs.core\/PROTOCOL_SENTINEL","cljs.core\/apply","cljs.core\/hash-map","cljs.core\/get","cljs-http.util\/build-url","scheme","server-name","server-port","uri","query-string","G__22301","goog\/Uri","cljs.core\/name","or__4131__auto__","cljs-http.util\/camelize","s","clojure.string\/split","clojure.string\/capitalize","clojure.string\/join","cljs-http.util\/build-headers","m","cljs.core\/clj->js","cljs.core\/zipmap","cljs.core\/keys","cljs.core\/vals","cljs-http.util\/user-agent","goog.userAgent\/getUserAgentString","cljs-http.util\/android?","cljs.core\/re-matches","cljs-http.util\/transit-decode","type","opts","rdr","cognitect.transit\/reader","cognitect.transit\/read","cljs-http.util\/transit-encode","x","wrtr","cognitect.transit\/writer","cognitect.transit\/write","cljs-http.util\/json-decode","v","clojure.string\/blank?","js\/JSON.parse","cljs.core\/js->clj","cljs-http.util\/json-encode","js\/JSON.stringify","cljs-http.util\/parse-headers","headers","p1__22303#","p2__22302#","cljs.core\/reduce","vec__22304","k","cljs.core\/assoc","clojure.string\/lower-case"]}