connection handler-case

This commit is contained in:
secretspecter 2023-08-14 22:50:36 -06:00
parent a77b2e06c0
commit 93c1b6cc4d

View file

@ -1,4 +1,5 @@
(in-package #:geml.server) (in-package #:geml.server)
(defun ensure-cert (certs-dir) (defun ensure-cert (certs-dir)
(lambda (setting) (lambda (setting)
(let* ((domain (string-downcase (symbol-name (car setting)))) (let* ((domain (string-downcase (symbol-name (car setting))))
@ -87,12 +88,14 @@
;; * https://en.wikipedia.org/wiki/Server_Name_Indication ;; * https://en.wikipedia.org/wiki/Server_Name_Indication
(let* ((domain (string-downcase (let* ((domain (string-downcase
(car (first (without-global settings))))) (car (first (without-global settings)))))
(tls-conn (cl+ssl:make-ssl-server-stream (tls-conn (handler-case (cl+ssl:make-ssl-server-stream
(usocket:socket-stream (usocket:socket-stream
(usocket:socket-accept server)) (usocket:socket-accept server))
:external-format '(:utf-8 :eol-style :crlf) :external-format '(:utf-8 :eol-style :crlf)
:certificate (format nil "~A~A.crt" certs-dir domain) :certificate (format nil "~A~A.crt" certs-dir domain)
:key (format nil "~A~A.key" certs-dir domain)))) :key (format nil "~A~A.key" certs-dir domain))
;; TODO handle more specific cases
(error (c) (format t "TLS Error: ~A~%" c)))))
(unwind-protect (unwind-protect
(handle-request tls-conn settings) (handle-request tls-conn settings)
(close tls-conn))))) (close tls-conn)))))