Permalink
Browse files

Merge remote-tracking branch 'ztellman/clj-1.3' into clj-1.3-content-…

…lenght
  • Loading branch information...
dajac committed Jan 25, 2012
2 parents 6a4cac6 + d648148 commit dbfd9c1d9bc0e797549a2094c45dbfd909636d86
View
@@ -1,4 +1,4 @@
(defproject aleph "0.2.1-SNAPSHOT"
(defproject aleph "0.2.1-alpha1"
:description "a framework for asynchronous communication"
:repositories {"jboss" "http://repository.jboss.org/nexus/content/groups/public/"}
:license {:name "Eclipse Public License - v 1.0"
@@ -8,10 +8,20 @@
[org.clojure/tools.logging "0.2.3"]
[org.clojure/data.json "0.1.1"]
[org.clojure.contrib/prxml "1.3.0-alpha4"]
[org.jboss.netty/netty "3.2.5.Final"]
[io.netty/netty "3.3.0.Final"]
[clj-http "0.1.3"]
[lamina "0.4.1-SNAPSHOT"]
[gloss "0.2.1-SNAPSHOT"]
[lamina "0.4.1-alpha1"]
[gloss "0.2.1-alpha1"]
[user-agent-utils "1.2.3"]
[potemkin "0.1.1-SNAPSHOT"]]
[potemkin "0.1.1"]]
:multi-deps {:all [[org.clojure/tools.logging "0.2.3"]
[org.clojure/data.json "0.1.1"]
[org.clojure.contrib/prxml "1.3.0-alpha4"]
[io.netty/netty "3.3.0.Final"]
[clj-http "0.1.3"]
[lamina "0.4.1-alpha1"]
[gloss "0.2.1-alpha1"]
[user-agent-utils "1.2.3"]
[potemkin "0.1.1"]]
"1.2" [[org.clojure/clojure "1.2.1"]]}
:jvm-opts ["-server" "-XX:+UseConcMarkSweepGC"])
View

This file was deleted.

Oops, something went wrong.
View
@@ -15,16 +15,14 @@
(:require
[aleph.http.server :as server]
[aleph.http.client :as client]
[aleph.http.utils :as utils]
[aleph.http.policy-file :as policy])
[aleph.http.utils :as utils])
(:import
[java.io InputStream]))
(import-fn server/start-http-server)
(import-fn client/http-client)
(import-fn client/pipelined-http-client)
(import-fn client/http-request)
(import-fn client/websocket-client)
(defn sync-http-request
"A synchronous version of http-request. Halts the thread until the response has returned,
@@ -34,8 +32,6 @@
([request timeout]
@(http-request request timeout)))
(import-fn policy/start-policy-file-server)
(defn wrap-aleph-handler
"Allows for an asynchronous handler to be used within a largely synchronous application.
Assuming the top-level handler has been wrapped in wrap-ring-handler, this function can be
View
@@ -14,8 +14,7 @@
[aleph.http.client requests responses]
[lamina core connections api])
(:require
[clj-http.client :as client]
[aleph.http.websocket.hixie :as hixie])
[clj-http.client :as client])
(:import
[java.util.concurrent
TimeoutException]
@@ -199,61 +198,3 @@
response)))
;;;
(defn websocket-handshake [protocol]
(wrap-client-request
{:method :get
:headers {"Sec-WebSocket-Key1" "18x 6]8vM;54 *(5: { U1]8 z [ 8" ;;TODO: actually randomly generate these
"Sec-WebSocket-Key2" "1_ tx7X d < nw 334J702) 7]o}` 0"
"Sec-WebSocket-Protocol" protocol
"Upgrade" "WebSocket"
"Connection" "Upgrade"}
:body (ByteBuffer/wrap (.getBytes "Tm[K T2u" "utf-8"))}))
(def expected-response (ByteBuffer/wrap (.getBytes "fQJ,fN/4F4!~K~MH" "utf-8")))
(defn websocket-pipeline [ch result options]
(create-netty-pipeline (:name options)
:decoder (HttpResponseDecoder.)
:encoder (HttpRequestEncoder.)
:handshake (message-stage
(fn [^Channel netty-channel ^HttpResponse rsp]
(if (not= 101 (-> rsp .getStatus .getCode))
(error! result (Exception. "Proper handshake not received."))
(let [pipeline (.getPipeline netty-channel)]
(.replace pipeline "decoder" "websocket-decoder" (WebSocketFrameDecoder.))
(.replace pipeline "encoder" "websocket-encoder" (WebSocketFrameEncoder.))
(.replace pipeline "handshake" "response"
(message-stage
(fn [netty-channel rsp]
(enqueue ch (hixie/from-websocket-frame rsp))
nil)))
(success! result ch)))
nil))))
(defn websocket-client [options]
(let [options (split-url options)
options (merge
{:name (str "websocket-client:" (:host options) ":" (gensym ""))}
options)
result (result-channel)
client (create-client
#(websocket-pipeline % result options)
identity
options)]
(run-pipeline client
(fn [ch]
(enqueue ch
(transform-aleph-request
(websocket-handshake (or (:protocol options) "aleph"))
(:scheme options)
(:server-name options)
(:server-port options)
options))
(run-pipeline result
(fn [_]
(let [in (channel)]
(siphon (map* hixie/to-websocket-frame in) ch)
(on-closed in #(close ch))
(splice ch in))))))))
@@ -11,22 +11,18 @@
[lamina.core.pipeline :only (closed-result)]
[lamina core]
[aleph formats]
[aleph.http core]
[aleph.core lazy-map])
[aleph.http core utils])
(:import
[org.jboss.netty.handler.codec.http
HttpResponse
HttpChunk]))
(defn transform-netty-response [^HttpResponse netty-response options]
(let [headers (delayed (netty-headers netty-response))
content-info (delayed (content-info netty-response))
content-length (delayed (content-length netty-response))
response (lazy-map
:headers headers
:content-encoding content-info
:content-type content-info
:content-length content-length
(let [response (lazy-map
:headers (delay (http-headers netty-response))
:character-encoding (delay (http-character-encoding netty-response))
:content-type (delay (http-content-type netty-response))
:content-length (delay (http-content-length netty-response))
:status (-> netty-response .getStatus .getCode))]
(assoc response
:body (.getContent netty-response))))
View
@@ -9,6 +9,7 @@
(ns ^{:skip-wiki true}
aleph.http.core
(:use
[potemkin]
[aleph netty formats]
[aleph.http utils]
[lamina.core]
@@ -45,20 +46,18 @@
;;;
(def keyword->request-method
{:get HttpMethod/GET
:put HttpMethod/PUT
:delete HttpMethod/DELETE
:post HttpMethod/POST
:trace HttpMethod/TRACE
:connect HttpMethod/CONNECT
:options HttpMethod/OPTIONS
:head HttpMethod/HEAD})
(def request-method->keyword
(zipmap
(vals keyword->request-method)
(keys keyword->request-method)))
(def-custom-map LazyMap
:get
(fn [_ data _ key default-value]
`(if-not (contains? ~data ~key)
~default-value
(let [val# (get ~data ~key)]
(if (delay? val#)
@val#
val#)))))
(defn lazy-map [& {:as m}]
(LazyMap. m))
;;;
@@ -132,46 +131,6 @@
;;;
(defn netty-headers
"Get headers from Netty message."
[^HttpMessage msg]
(fn [_]
{:headers (let [headers (into {} (.getHeaders msg))]
(into {}
(map
(fn [[k v]] [(str/lower-case k) v])
(into {} (.getHeaders msg)))))}))
(defn netty-request-method
"Get HTTP method from Netty request."
[^HttpRequest req]
(fn [_]
{:request-method (->> req .getMethod request-method->keyword)}))
(defn netty-request-uri
"Get URI from Netty request."
[^HttpRequest req]
(fn [_]
(let [paths (.split (.getUri req) "[?]")]
{:uri (first paths)
:query-string (second paths)})))
(defn content-length [_]
(fn [msg]
(let [headers (:headers msg)]
(when-let [content-length (or (get headers "content-length") (get headers "Content-Length"))]
{:content-length (Integer/parseInt content-length)}))))
(defn content-info [_]
(fn [msg]
(let [headers (:headers msg)]
(when-let [content-type (or (get headers "content-type") (get headers "Content-Type"))]
{:content-type content-type
:character-encoding (->> (str/split content-type #"[;=]")
(map str/trim)
(drop-while #(not= % "charset"))
second)}))))
(defn pre-process-aleph-message [msg options]
(update-in msg [:headers]
(fn [headers]
Oops, something went wrong.

0 comments on commit dbfd9c1

Please sign in to comment.