Browse files

potemkin can provide the lazy-map, and get rid of all the stuff we do…

…n't need anymore
  • Loading branch information...
ztellman committed Jan 25, 2012
1 parent 64dfb16 commit 46c5bacca8887c5aa69da755260b789a06ec5526

This file was deleted.

Oops, something went wrong.
@@ -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])
(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))))
@@ -9,6 +9,7 @@
(ns ^{:skip-wiki true}
[aleph netty formats]
[aleph.http utils]
@@ -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
(vals keyword->request-method)
(keys keyword->request-method)))
(def-custom-map LazyMap
(fn [_ data _ key default-value]
`(if-not (contains? ~data ~key)
(let [val# (get ~data ~key)]
(if (delay? 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 {}
(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"))
(defn pre-process-aleph-message [msg options]
(update-in msg [:headers]
(fn [headers]
@@ -10,8 +10,7 @@
[lamina core connections executors api]
[aleph netty formats]
[aleph.core lazy-map]
[aleph.http core])
[aleph.http core utils])
@@ -33,24 +32,18 @@
(defn transform-netty-request
"Transforms a Netty request into a Ring request."
[^HttpRequest req netty-channel options]
(let [destination (delayed (request-destination req))
headers (delayed (netty-headers req))
content-info (delayed (content-info req))
content-length (delayed (content-length req))
request-method (delayed (netty-request-method req))
uri (delayed (netty-request-uri req))
request (lazy-map
(let [request (lazy-map
:scheme :http
:remote-addr (channel-origin netty-channel)
:headers headers
:server-name destination
:uri uri
:query-string uri
:server-port destination
:content-type content-info
:character-encoding content-info
:content-length content-length
:request-method request-method)]
:remote-addr (delay (channel-remote-host-address netty-channel))
:headers (delay (http-headers req))
:server-name (delay (channel-local-host-address netty-channel))
:uri (delay (request-uri req))
:query-string (delay (request-query-string req))
:server-port (delay (channel-local-port netty-channel))
:content-type (delay (http-content-type req))
:character-encoding (delay (http-character-encoding req))
:content-length (delay (http-content-length req))
:request-method (delay (request-method req)))]
(assoc request
:body (if (.isChunked req)
@@ -160,7 +160,10 @@
(defn respond [^Channel netty-channel options returned-result response]
(let [response (pre-process-aleph-message response options)
response (update-in response [:headers] (partial merge {"Server" "aleph (0.2.0)"}))
response (merge ((content-info nil) response) response)
response (merge
{:content-type (http-content-type response)
:character-encoding (http-character-encoding response)}
body (:body response)]
(nil? body)
Oops, something went wrong.

0 comments on commit 46c5bac

Please sign in to comment.