Skip to content

Commit

Permalink
fixup! fixup! m2 init
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenet committed Sep 15, 2023
1 parent 7a3b5d6 commit b6bd2ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ middlewares out there.

* `:port` - port the server listens to, defaults to random free port

* `:default-socket` - map-of `:write-queue-length` `:backlog` `:max-payload-size` `:receive-buffer-size` `:connection-options`(map-of `:socket-receive-buffer-size` `:socket-send-buffer-size` `:socket-reuse-address` `:socket-keep-alive` `:tcp-no-delay` `:read-timeout` `:connect-timeout`)
* `:write-queue-length`

* `:backlog`

* `:max-payload-size`

* `:write-queue-length`

* `:receive-buffer-size`

* `:connection-options`(map-of `:socket-receive-buffer-size` `:socket-send-buffer-size` `:socket-reuse-address` `:socket-keep-alive` `:tcp-no-delay` `:read-timeout` `:connect-timeout`)

* `:tls` - A `io.helidon.nima.common.tls.Tls` instance

Expand All @@ -49,8 +59,7 @@ it will do the protocol switch automatically.

## Installation

Note: You need to use java20 and add `:jvm-opts ["--enable-preview"]` to the
alias you will use to be able to run it.
Note: You need to use java **21**

https://clojars.org/com.s-exp/mina

Expand Down
6 changes: 4 additions & 2 deletions src/s_exp/mina.clj
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
;; (def r {:status 200})
;; (def h (fn [req]
;; (prn (counted? (:headers req)))
;; r))
;; r))
;; (def h (fn [_]
;; ;; (prn :aasdf ((:headers _) "accept"))
;; ;; (prn (:headers _))
;; r))
;; (def s (start!
;; r
;; {:host "0.0.0.0" :port 8080 :default-socket {:write-queue-length 10240}}))
;; {:host "0.0.0.0" :port 8080
;; :write-queue-length 10240
;; :connection-options {:socket-send-buffer-size 1024}}))

;; (stop! s)

Expand Down
15 changes: 6 additions & 9 deletions src/s_exp/mina/options.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(ns s-exp.mina.options
(:import (io.helidon.common.socket SocketOptions$Builder)
(io.helidon.common.tls TlsConfig)
(io.helidon.webserver ListenerConfig$Builder
WebServerConfig$Builder)
(io.helidon.common.tls Tls)
(io.helidon.webserver WebServerConfig$Builder)
(java.time Duration)))

(set! *warn-on-reflection* true)

(defmulti set-server-option! (fn [_builder k _v _options] k))

(defmethod set-server-option! :default [builder _ _ _]
Expand All @@ -23,10 +23,6 @@
[^WebServerConfig$Builder builder _ backlog _]
(.backlog builder (int backlog)))

(defmethod set-server-option! :backlog
[^WebServerConfig$Builder builder _ backlog _]
(.backlog builder (int backlog)))

(defmethod set-server-option! :max-payload-size
[^WebServerConfig$Builder builder _ max-payload-size _]
(.maxPayloadSize builder (long max-payload-size)))
Expand Down Expand Up @@ -75,11 +71,12 @@
(.connectionOptions builder
(reify java.util.function.Consumer
(accept [_ socket-options-builder]
(prn :sob socket-options-builder)
(set-connection-options! socket-options-builder
connection-options)))))

(defmethod set-server-option! :tls
[^WebServerConfig$Builder builder _ ^TlsConfig tls-config _]
(doto builder (.tls tls-config)))
[^WebServerConfig$Builder builder _ tls-config _]
(doto builder (.tls ^Tls tls-config)))


52 changes: 22 additions & 30 deletions test/s_exp/mina_test.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(ns s-exp.mina-test
"Tests vars run in parallel"
(:require [clj-http.client :as client]
[clojure.string :as str]
[clojure.test :refer :all]
[less.awful.ssl :as ls]
[s-exp.mina :as m])
;; (:import (io.helidon.nima.common.tls Tls TlsClientAuth))
)
(:import (io.helidon.common.tls Tls TlsClientAuth)
(io.helidon.common.tls TlsConfig)))

(def ^:dynamic *endpoint*)

Expand Down Expand Up @@ -75,33 +74,26 @@
(with-server {:handler (fn [req] {:body (java.io.ByteArrayInputStream. (.getBytes "yes"))})}
(is (-> (client/get *endpoint*) :body (= "yes")))))

#_(defn tls []
(-> (Tls/builder)
(.tlsClientAuth TlsClientAuth/REQUIRED)
(.trustAll true)
(.sslContext (ls/ssl-context "test/server.key"
"test/server.crt"
"test/server.crt"))
(.endpointIdentificationAlgorithm (Tls/ENDPOINT_IDENTIFICATION_NONE))
(.build)))

#_(deftest test-ssl-context
(with-server {:handler (fn [req] {})
:tls (tls)}
(let [endpoint (str/replace *endpoint* "http://" "https://")]
(is (thrown? Exception (client/get endpoint)))
(is (status-ok? (client/get endpoint {:insecure? true})))
(is (status-ok? (client/get endpoint
{:insecure? true
:keystore "test/keystore.jks"
:keystore-pass "password"
:trust-store "test/keystore.jks"
:trust-store-pass "password"})))))

(with-server {:handler (fn [req] {:body (str (:scheme req))}) :tls (tls)}
(is (-> (client/get (str/replace *endpoint* "http" "https")
{:insecure? true})
:body (= ":https")))))
(defn tls []
(let [b (doto (TlsConfig/builder)
(.sslContext (ls/ssl-context "test/server.key"
"test/server.crt"
"test/server.crt"))
(.clientAuth TlsClientAuth/REQUIRED)
(.trustAll true)
(.endpointIdentificationAlgorithm (Tls/ENDPOINT_IDENTIFICATION_NONE)))]
(.build b)))

(deftest test-ssl-context
(with-server {:handler (fn [req] {}) :tls (tls)}
(let [endpoint (str/replace *endpoint* "http://" "https://")]
(is (thrown? Exception (client/get endpoint)))
(is (status-ok? (client/get endpoint
{:insecure? true
:keystore "test/keystore.jks"
:keystore-pass "password"
:trust-store "test/keystore.jks"
:trust-store-pass "password"}))))))



0 comments on commit b6bd2ee

Please sign in to comment.