Permalink
Browse files

Merge branch 'master' of git://github.com/marktriggs/clojure-http-cli…

…ent into lein
  • Loading branch information...
2 parents d79c8ef + 1338ca0 commit 03be9bccd86e3da09d6fc6f0c2d8c40ce4519cee @technomancy technomancy committed Dec 1, 2009
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/clojure/http/client.clj
View
15 src/clojure/http/client.clj
@@ -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)
@@ -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)
@@ -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))

0 comments on commit 03be9bc

Please sign in to comment.