cch1 / http.async.client

Async Http Client - Clojure
http://cch1.github.com/http.async.client
267 stars 40 forks source link

Add preemptive authorization #15

Closed xeqi closed 13 years ago

xeqi commented 13 years ago

I was trying to use this to hit the campfire api (http://developer.37signals.com/campfire/streaming), and their streaming server does not request authentication. It just expects you to send the request with authentication.

I've added {:preemptive boolean} to the auth map to allow for preemptive authorization, so that the library does not require the challenge first. I left the default to false. Perhaps using the auth map should default to true, but I did not want to introduce a behavior change.

neotyk commented 13 years ago

Thank you, already merged :-)

devth commented 12 years ago

Stumbled upon this awesome addition today.

@xeqi - were you ever able to get this working with campfire's streaming API? I'm trying to do so and only get Access Denied Token or room not found responses, even though I was able to join the room using http.async.client.

(let [resp (c/stream-seq client :get "https://streaming.campfirenow.com/room/[my room id]/live.json"
                                  :auth {:user u :password p}
                                  :preemptive true)]
    (doseq [s (c/string resp)]
     (println s)))

Running on 0.3.1

xeqi commented 12 years ago

I did. Thats the error message you'll get when it isn't doing preemptive auth. The streaming.campfirenow.com server doesn't challenge for non-preemptive, where as the normal server does. Made it fun to track down.

The :preemptive key is in the wrong place. Try:

(let [resp (c/stream-seq client :get "https://streaming.campfirenow.com/room/[my room id]/live.json"
                                :auth {:user u :password p :preemptive true})]
    (doseq [s (c/string resp)]
     (println s)))
devth commented 12 years ago

Ah, missed that. Thanks much, working now!