Remove the web-server exception handler

This turned out not to be useful, since I wanted to handle exceptions
happening in the exception handler, so it didn't really help in the
end to allow customising it.
This commit is contained in:
Christopher Baines 2025-03-14 14:27:29 +00:00
parent da69fd19f3
commit e1858dfff5
2 changed files with 9 additions and 82 deletions

View file

@ -48,7 +48,6 @@
request-body-port/knots
read-request-body/knots
default-exception-handler
default-write-response-exception-handler
web-server?
@ -310,7 +309,7 @@ on the procedure being called at any particular time."
;; Close the client port
#f)
(define (default-exception-handler exn request)
(define (exception-handler exn request)
(let* ((error-string
(call-with-output-string
(lambda (port)
@ -332,8 +331,7 @@ on the procedure being called at any particular time."
(define (handle-request handler client
read-request-exception-handler
write-response-exception-handler
exception-handler)
write-response-exception-handler)
(let ((request
(with-exception-handler
read-request-exception-handler
@ -356,58 +354,14 @@ on the procedure being called at any particular time."
(lambda (return)
(with-exception-handler
(lambda (exn)
(with-exception-handler
(lambda (exn)
(call-with-values
(lambda ()
(default-exception-handler
(make-exception
exn
(make-exception-with-message
"exception in exception handler")
(make-exception-with-irritants
exception-handler))
request))
(match-lambda*
((response body)
(call-with-values
(lambda ()
(sanitize-response
request
response
body))
return)))))
(lambda ()
(call-with-values
(lambda ()
(exception-handler exn request))
(lambda (response body)
(call-with-values
(lambda ()
(exception-handler exn request))
(match-lambda*
((response body)
(call-with-values
(lambda ()
(sanitize-response request response body))
return))
(other
(call-with-values
(lambda ()
(default-exception-handler
(make-exception-with-irritants
(list (make-exception-with-message
(simple-format
#f
"wrong number of values returned from exception handler, expecting 2, got ~A"
(length other)))
exception-handler))
request))
(match-lambda*
((response body)
(call-with-values
(lambda ()
(sanitize-response
request
response
body))
return))))))))))
(sanitize-response request response body))
return))))
(lambda ()
(start-stack
#t
@ -475,7 +429,6 @@ on the procedure being called at any particular time."
#:unwind? #t))))
(define* (client-loop client handler
exception-handler
read-request-exception-handler
write-response-exception-handler
connection-idle-timeout
@ -517,8 +470,7 @@ on the procedure being called at any particular time."
(else
(let ((keep-alive? (handle-request handler client
read-request-exception-handler
write-response-exception-handler
exception-handler)))
write-response-exception-handler)))
(if keep-alive?
(loop)
(close-port client)))))))
@ -537,8 +489,6 @@ on the procedure being called at any particular time."
INADDR_LOOPBACK))
(port 8080)
(socket (make-default-socket family addr port))
(exception-handler
default-exception-handler)
(read-request-exception-handler
default-read-request-exception-handler)
(write-response-exception-handler
@ -577,7 +527,6 @@ before sending back to the client."
((client . sockaddr)
(spawn-fiber (lambda ()
(client-loop client handler
exception-handler
read-request-exception-handler
write-response-exception-handler
connection-idle-timeout

View file

@ -52,28 +52,6 @@
uri
#:port (non-blocking-open-socket-for-uri uri)))))))
(run-fibers-for-tests
(lambda ()
(let* ((web-server
(run-knots-web-server
(lambda (request)
"Hello, World!")
#:port 0
#:exception-handler
(lambda (exn request)
"Error"))) ;; Bind to any port
(port
(web-server-port web-server))
(uri
(build-uri 'http #:host "127.0.0.1" #:port port)))
(assert-equal
500
(response-code
(http-get
uri
#:port (non-blocking-open-socket-for-uri uri)))))))
(run-fibers-for-tests
(lambda ()
(let* ((web-server