Skip to content

Commit d33c76d

Browse files
authored
Merge pull request #398 from kachayev/fix-cleanup-2
Cleanups
2 parents 0319133 + a87be7e commit d33c76d

File tree

4 files changed

+16
-72
lines changed

4 files changed

+16
-72
lines changed

src/aleph/http/core.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,22 @@
193193
(if (neg? idx)
194194
(.getUri req)
195195
(.substring (.getUri req) 0 idx)))
196-
:query-string (let [uri (.getUri req)]
196+
:query-string (let [uri (.uri req)]
197197
(if (neg? question-mark-index)
198198
nil
199199
(.substring uri (unchecked-inc question-mark-index))))
200200
:headers (-> req .headers headers->map)
201-
:request-method (-> req .getMethod .name str/lower-case keyword)
201+
:request-method (-> req .method .name str/lower-case keyword)
202202
:body body
203203
:scheme (if ssl? :https :http)
204-
:aleph/keep-alive? (HttpHeaders/isKeepAlive req)
204+
:aleph/keep-alive? (HttpUtil/isKeepAlive req)
205205
:server-name (netty/channel-server-name ch)
206206
:server-port (netty/channel-server-port ch)
207207
:remote-addr (netty/channel-remote-address ch))
208208

209209
(p/def-derived-map NettyResponse [^HttpResponse rsp complete body]
210-
:status (-> rsp .getStatus .code)
211-
:aleph/keep-alive? (HttpHeaders/isKeepAlive rsp)
210+
:status (-> rsp .status .code)
211+
:aleph/keep-alive? (HttpUtil/isKeepAlive rsp)
212212
:headers (-> rsp .headers headers->map)
213213
:aleph/complete complete
214214
:body body)
@@ -220,7 +220,7 @@
220220
ssl?
221221
ch
222222
(AtomicBoolean. false)
223-
(-> req .getUri (.indexOf (int 63))) body)
223+
(-> req .uri (.indexOf (int 63))) body)
224224
:aleph/request-arrived (System/nanoTime)))
225225

226226
(defn netty-response->ring-response [rsp complete body]
@@ -238,7 +238,7 @@
238238
(def empty-last-content LastHttpContent/EMPTY_LAST_CONTENT)
239239

240240
(let [ary-class (class (byte-array 0))]
241-
(defn coerce-element [ch x]
241+
(defn coerce-element [x]
242242
(if (or
243243
(instance? String x)
244244
(instance? ary-class x)
@@ -259,7 +259,7 @@
259259

260260
(let [buf (netty/allocate ch)
261261
pending? (instance? clojure.lang.IPending body)]
262-
(loop [s (map (partial coerce-element ch) body)]
262+
(loop [s (map coerce-element body)]
263263
(cond
264264

265265
(and pending? (not (realized? s)))
@@ -368,7 +368,7 @@
368368

369369
(when-not omitted?
370370
(if (instance? HttpResponse msg)
371-
(let [code (-> ^HttpResponse msg .getStatus .code)]
371+
(let [code (-> ^HttpResponse msg .status .code)]
372372
(when-not (or (<= 100 code 199) (= 204 code))
373373
(try-set-content-length! msg length)))
374374
(try-set-content-length! msg length)))

src/aleph/http/server.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
[io.netty.handler.stream ChunkedWriteHandler]
3232
[io.netty.handler.codec.http
3333
DefaultFullHttpResponse
34-
HttpContent HttpHeaders
34+
HttpContent HttpHeaders HttpUtil
3535
HttpContentCompressor
3636
HttpRequest HttpResponse
3737
HttpResponseStatus DefaultHttpHeaders
@@ -358,7 +358,7 @@
358358
req
359359
@previous-response
360360
body
361-
(HttpHeaders/isKeepAlive req))))]
361+
(HttpUtil/isKeepAlive req))))]
362362
(netty/channel-inbound-handler
363363

364364
:exception-caught

src/aleph/netty.clj

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@
627627
(.write ctx msg promise)))))
628628

629629
(defn pipeline-initializer [pipeline-builder]
630-
(channel-handler
630+
(channel-inbound-handler
631631

632632
:channel-registered
633633
([this ctx]
@@ -638,8 +638,7 @@
638638
(.fireChannelRegistered ctx)
639639
(catch Throwable e
640640
(log/warn e "Failed to initialize channel")
641-
(.close ctx))))
642-
(.fireChannelRegistered ctx))))
641+
(.close ctx)))))))
643642

644643
(defn instrument!
645644
[stream]
@@ -656,61 +655,6 @@
656655

657656
;;;
658657

659-
(potemkin/def-map-type HeaderMap
660-
[^Headers headers
661-
added
662-
removed
663-
mta]
664-
(meta [_]
665-
mta)
666-
(with-meta [_ m]
667-
(HeaderMap.
668-
headers
669-
added
670-
removed
671-
m))
672-
(keys [_]
673-
(set/difference
674-
(set/union
675-
(set (map str/lower-case (.names headers)))
676-
(set (keys added)))
677-
(set removed)))
678-
(assoc [_ k v]
679-
(HeaderMap.
680-
headers
681-
(assoc added k v)
682-
(disj removed k)
683-
mta))
684-
(dissoc [_ k]
685-
(HeaderMap.
686-
headers
687-
(dissoc added k)
688-
(conj (or removed #{}) k)
689-
mta))
690-
(get [_ k default-value]
691-
(if (contains? removed k)
692-
default-value
693-
(if-let [e (find added k)]
694-
(val e)
695-
(let [k' (str/lower-case (name k))
696-
vs (.getAll headers k')]
697-
(if (.isEmpty vs)
698-
default-value
699-
(if (p/== 1 (.size vs))
700-
(.get vs 0)
701-
(reduce
702-
(fn [v s]
703-
(if v
704-
(str v "," s)
705-
s)
706-
vs)
707-
nil))))))))
708-
709-
(defn headers [^Headers h]
710-
(HeaderMap. h nil nil nil))
711-
712-
;;;
713-
714658
(defn self-signed-ssl-context
715659
"A self-signed SSL context for servers."
716660
[]

test/aleph/http_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189

190190
(deftest test-response-formats
191191
(with-handler basic-handler
192-
(doseq [[index [path result]] (map vector (iterate inc 0) expected-results)]
192+
(doseq [[index [path result]] (map-indexed vector expected-results)]
193193
(is
194194
(= result
195195
(bs/to-string
@@ -198,7 +198,7 @@
198198

199199
(deftest test-compressed-response
200200
(with-compressed-handler basic-handler
201-
(doseq [[index [path result]] (map vector (iterate inc 0) expected-results)
201+
(doseq [[index [path result]] (map-indexed vector expected-results)
202202
:let [resp @(http-get (str "http://localhost:" port "/" path)
203203
{:headers {:accept-encoding "gzip"}})
204204
unzipped (try
@@ -210,7 +210,7 @@
210210

211211
(deftest test-ssl-response-formats
212212
(with-ssl-handler basic-handler
213-
(doseq [[index [path result]] (map vector (iterate inc 0) expected-results)]
213+
(doseq [[index [path result]] (map-indexed vector expected-results)]
214214
(is
215215
(= result
216216
(bs/to-string

0 commit comments

Comments
 (0)