Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/marktriggs/clojure-http-cli…
Browse files Browse the repository at this point in the history
…ent into lein
  • Loading branch information
technomancy committed Dec 1, 2009
2 parents d79c8ef + 1338ca0 commit 03be9bc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/clojure/http/client.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns clojure.http.client
(:use [clojure.contrib.java-utils :only [as-str]]
[clojure.contrib.duck-streams :only [read-lines spit]]
[clojure.contrib.str-utils :only [str-join]])
[clojure.contrib.str-utils :only [str-join]]
[clojure.contrib.base64 :as base64])
(:import (java.net URL
URLEncoder
HttpURLConnection)
Expand Down Expand Up @@ -106,8 +107,9 @@ by a server."
[u & [method headers cookies body]]
;; This function *should* throw an exception on non-HTTP URLs.
;; This will happen if the cast fails.
(let [#^HttpURLConnection connection
(cast HttpURLConnection (.openConnection (url u)))
(let [u (url u)
#^HttpURLConnection connection
(cast HttpURLConnection (.openConnection u))
method (.toUpperCase #^String (as-str (or method
"GET")))]
(.setRequestMethod connection method)
Expand All @@ -122,6 +124,13 @@ by a server."
(.setRequestProperty connection
"Cookie"
(create-cookie-string cookies)))

(when (.getUserInfo u)
(.setRequestProperty connection
"Authorization"
(str "Basic "
(base64/encode-str (.getUserInfo u)))))

(if body
(send-body body connection headers)
(.connect connection))
Expand Down

0 comments on commit 03be9bc

Please sign in to comment.