Skip to content

Commit

Permalink
Update to microhttp 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
bowbahdoe committed Sep 12, 2023
1 parent 84e41c3 commit b3c3075
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ worth noting.
This was done as a proof of concept, but the code is simple enough that
I am confident it is as production ready as microhttp.

That being said, I'm gonna put breaking changes in willy-nilly until it is
published to maven central.

## deps.edn

```clojure
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{:paths ["src"]
:deps {ring/ring-core {:mvn/version "1.9.5"}
org.microhttp/microhttp {:mvn/version "0.7"}}}
org.microhttp/microhttp {:mvn/version "0.10"}}}
46 changes: 22 additions & 24 deletions src/dev/mccue/microhttp_ring_adapter.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dev.mccue.microhttp-ring-adapter
(:require [clojure.string :as string]
[ring.core.protocols :as ring-protocols])
(:import (org.microhttp Request Handler Response Header EventLoop Options DebugLogger Logger)
(:import (org.microhttp NoopLogger OptionsBuilder Request Handler Response Header EventLoop Options DebugLogger Logger)
(java.io ByteArrayInputStream ByteArrayOutputStream)
(java.util.concurrent ForkJoinPool ExecutorService)))

Expand Down Expand Up @@ -104,39 +104,37 @@
([handler]
(create-event-loop handler {}))
([handler options]
(let [microhttp-options (cond-> (Options.)
(contains? options :host)
(.withHost (:host options))
(let [microhttp-options-builder (cond-> (OptionsBuilder/newBuilder)
(contains? options :host)
(.withHost (:host options))

(some? (options :port))
(.withPort (:port options))
(some? (options :port))
(.withPort (:port options))

(some? (options :reuse-addr))
(.withReuseAddr (:reuse-addr options))
(some? (options :reuse-addr))
(.withReuseAddr (:reuse-addr options))

(some? (options :reuse-port))
(.withReusePort (:reuse-port options))
(some? (options :reuse-port))
(.withReusePort (:reuse-port options))

(some? (options :resolution))
(.withResolution (:resolution options))
(some? (options :resolution))
(.withResolution (:resolution options))

(some? (options :request-timeout))
(.withRequestTimeout (:request-timeout options))
(some? (options :request-timeout))
(.withRequestTimeout (:request-timeout options))

(some? (options :read-buffer-size))
(.withReadBufferSize (:read-buffer-size options))
(some? (options :read-buffer-size))
(.withReadBufferSize (:read-buffer-size options))

(some? (options :accept-length))
(.withAcceptLength (:accept-length options))
(some? (options :accept-length))
(.withAcceptLength (:accept-length options))

(some? (options :max-request-size))
(.withMaxRequestSize (:max-request-size options)))
(some? (options :max-request-size))
(.withMaxRequestSize (:max-request-size options)))
microhttp-options (.build microhttp-options-builder)
microhttp-logger (or (:logger options) (if (:debug options)
(DebugLogger.)
(reify Logger
(enabled [_] false)
(log [_ _])
(log [_ _ _]))))
(NoopLogger/instance)))
executor (or (:executor options) (ForkJoinPool/commonPool))]
(EventLoop. microhttp-options
microhttp-logger
Expand Down

0 comments on commit b3c3075

Please sign in to comment.