run-httpcore

ring.adapter.httpcore

  • (run-httpcore handler {:keys [port server-name server-port execute]})
Serve the given handler according to the options.
Options:
:port
:server-name - For old HTTP/1.0 clients
:server-port - For old HTTP/1.0 clients, when public facing port is different
from :port
:execute - Function with signature [f & args] that applies f to args,
usually in another thread

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source ring/adapter/httpcore.clj:167 top

(defn run-httpcore
 "Serve the given handler according to the options.
 Options:
   :port      
   :server-name - For old HTTP/1.0 clients
   :server-port - For old HTTP/1.0 clients, when public facing port is different
                  from :port
   :execute     - Function with signature [f & args] that applies f to args,
                  usually in another thread"
 [handler {:keys [port server-name server-port execute]}]
  (let [execute (or execute (partial executor-execute
                              (Executors/newCachedThreadPool
                                (proxy [ThreadFactory] []
                                  (newThread [r]
                                    (doto (Thread. #^Runnable r)
                                      (.setDaemon true)))))))
        params (doto (BasicHttpParams.)
                 (.setIntParameter CoreConnectionPNames/SO_TIMEOUT 5000)
                 (.setIntParameter CoreConnectionPNames/SOCKET_BUFFER_SIZE (* 8 1024))
                 (.setBooleanParameter CoreConnectionPNames/STALE_CONNECTION_CHECK false)
                 (.setBooleanParameter CoreConnectionPNames/TCP_NODELAY true))
        httpservice (create-http-service handler)
        request-prototype {:scheme :http :server-port (or server-port port) :server-name server-name}]
    (with-open [serversocket (ServerSocket. port)]
      (while (not (.isInterrupted (Thread/currentThread)))
        (let [socket (.accept serversocket)
              conn (doto (DefaultHttpServerConnection.)
                     (.bind socket params))]
          (execute handle-request httpservice conn
            (assoc request-prototype :remote-addr (-> socket .getInetAddress .getHostAddress))))))))
Vars in ring.adapter.httpcore/run-httpcore: -> assoc defn let not while with-open
Used in 0 other vars

Comments top

No comments for run-httpcore. Log in to add a comment.