cch1 / http.async.client

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

vector of bytes is piece of shit #1

Closed zahardzhan closed 14 years ago

zahardzhan commented 14 years ago

You use an a vector of bytes to collect response body, but i found it too bad design. I have exception when i try to get body of page in Russian lang, i think it is because of troubles with Unicode in your client. Can you use stream of bytes instead vector of bytes, like in clojure.contrib.http.client?

(apply str (map char (:body @(HTTP/GET "http://gettingreal.37signals.com/GR_rus.php"))))

java.lang.IllegalArgumentException: Value out of range for char: -48

neotyk commented 14 years ago

Thanks for you interest in ahc-clj.

Will look into this issue this evening.

neotyk commented 14 years ago

Please check http://github.com/neotyk/ahc-clj/blob/837773f72dc7f68f1f32f7d58eecfd0ba8403205/test/async/http/client/test.clj#L288 This issue is not a bug in a client, you tried to create chars out of bytes, that was core of the issue.

Note that: String. (byte-array (:body @resp)) "UTF-8") does the job properly.

Could you also provide a sample of how you would like to consume InputStream?

neotyk commented 14 years ago

will be moving implementation to use ByteArrayOutputStream and providing helper fns to read from it.

zahardzhan commented 14 years ago

Here the only place where i use input stream in my programs: http://github.com/zahardzhan/leica/blob/simplify/src/simplify.clj#L260

The best way to use it with your client i see: (with-open [input (:stream @(GET link))] ...)

neotyk commented 14 years ago

Please look into issue-1 branch at proposed solution.

Basically if you wan't string: (string (GET url))

http://github.com/neotyk/ahc-clj/blob/issue-1/test/async/http/client/test.clj#L282

zahardzhan commented 14 years ago

Thank you. Upload new version to clojars please.

neotyk commented 14 years ago

You are welcome and thank you very much for your feedback. New version will get released as soon as we release Async Http Client Java, as current 0.2.0-SNAPSHOT of ahc-clj depends on fixes that have to be released in Async Http Client Java.