mirror of https://codeberg.org/cage/tinmop/
- [GUI] added timeout test for dummy server;
- [GUI] returned a more useful error message to user when a timeout occurred.
This commit is contained in:
parent
b7e139a205
commit
904fb6cf7e
|
@ -421,13 +421,24 @@
|
||||||
#+debug-gemini-request
|
#+debug-gemini-request
|
||||||
(apply #'misc:dbg (text-utils:strcat "[gemini] " (first data)) (rest data)))
|
(apply #'misc:dbg (text-utils:strcat "[gemini] " (first data)) (rest data)))
|
||||||
|
|
||||||
|
#+sbcl
|
||||||
|
(define-constant +open-socket-response-deadline+ 10
|
||||||
|
:test #'=
|
||||||
|
:documentation "timeout, in seconds, for opening socket")
|
||||||
|
|
||||||
(defun open-tls-socket (host port)
|
(defun open-tls-socket (host port)
|
||||||
(flet ((open-socket (hostname)
|
(flet ((open-socket (hostname)
|
||||||
(usocket:socket-connect hostname
|
(usocket:socket-connect hostname
|
||||||
port
|
port
|
||||||
:element-type '(unsigned-byte 8))))
|
:element-type '(unsigned-byte 8))))
|
||||||
(or (ignore-errors (open-socket host))
|
#+sbcl (sb-sys:with-deadline (:seconds +open-socket-response-deadline+)
|
||||||
(open-socket (idn:host-unicode->ascii host)))))
|
(open-socket (idn:host-unicode->ascii host)))
|
||||||
|
#-sbcl (open-socket (idn:host-unicode->ascii host))))
|
||||||
|
|
||||||
|
#+sbcl
|
||||||
|
(define-constant +read-response-deadline+ 10
|
||||||
|
:test #'=
|
||||||
|
:documentation "timeout, in seconds, for reading response from remote server")
|
||||||
|
|
||||||
(defun request (host path &key
|
(defun request (host path &key
|
||||||
(query nil)
|
(query nil)
|
||||||
|
@ -443,6 +454,7 @@
|
||||||
:fragment (percent-encode-fragment fragment)))
|
:fragment (percent-encode-fragment fragment)))
|
||||||
(ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+)))
|
(ctx (cl+ssl:make-context :verify-mode cl+ssl:+ssl-verify-none+)))
|
||||||
(cl+ssl:with-global-context (ctx :auto-free-p t)
|
(cl+ssl:with-global-context (ctx :auto-free-p t)
|
||||||
|
(handler-case
|
||||||
(let ((socket (open-tls-socket host port)))
|
(let ((socket (open-tls-socket host port)))
|
||||||
(hooks:run-hooks 'hooks:*after-gemini-socket*)
|
(hooks:run-hooks 'hooks:*after-gemini-socket*)
|
||||||
(let* ((stream (usocket:socket-stream socket))
|
(let* ((stream (usocket:socket-stream socket))
|
||||||
|
@ -469,8 +481,12 @@
|
||||||
(force-output ssl-stream)
|
(force-output ssl-stream)
|
||||||
(hooks:run-hooks 'hooks:*after-gemini-request-sent*)
|
(hooks:run-hooks 'hooks:*after-gemini-request-sent*)
|
||||||
(multiple-value-bind (status description meta response)
|
(multiple-value-bind (status description meta response)
|
||||||
(parse-response ssl-stream)
|
#+sbcl (sb-sys:with-deadline (:seconds +read-response-deadline+)
|
||||||
(values status description meta response socket)))))))))
|
(parse-response ssl-stream))
|
||||||
|
#-sbcl (parse-response ssl-stream)
|
||||||
|
(values status description meta response socket))))))
|
||||||
|
(error (e)
|
||||||
|
(error e))))))
|
||||||
|
|
||||||
(defun missing-dispath-function (status code-description meta response socket iri parsed-iri)
|
(defun missing-dispath-function (status code-description meta response socket iri parsed-iri)
|
||||||
(declare (ignore response socket parsed-iri))
|
(declare (ignore response socket parsed-iri))
|
||||||
|
|
|
@ -58,7 +58,11 @@ and key stored in the file pointed by the filesystem path
|
||||||
"request ~s fingerprint ~a~%"
|
"request ~s fingerprint ~a~%"
|
||||||
request
|
request
|
||||||
client-cert-fingerprint)
|
client-cert-fingerprint)
|
||||||
(if (null client-cert-fingerprint)
|
(cond
|
||||||
|
((cl-ppcre:scan "timeout" request)
|
||||||
|
(format t "timeout...~%")
|
||||||
|
(sleep 3600))
|
||||||
|
((null client-cert-fingerprint)
|
||||||
(let ((response (format nil
|
(let ((response (format nil
|
||||||
"~a please provide a certificate~a~a"
|
"~a please provide a certificate~a~a"
|
||||||
(code gemini-client::+60+)
|
(code gemini-client::+60+)
|
||||||
|
@ -67,7 +71,8 @@ and key stored in the file pointed by the filesystem path
|
||||||
(write-sequence (text-utils:string->octets response)
|
(write-sequence (text-utils:string->octets response)
|
||||||
stream)
|
stream)
|
||||||
(close stream)
|
(close stream)
|
||||||
(get-data))
|
(get-data)))
|
||||||
|
(t
|
||||||
(let ((response (format nil
|
(let ((response (format nil
|
||||||
"~a text/gemini~a~a#OK~%"
|
"~a text/gemini~a~a#OK~%"
|
||||||
(code gemini-client::+20+)
|
(code gemini-client::+20+)
|
||||||
|
@ -76,5 +81,5 @@ and key stored in the file pointed by the filesystem path
|
||||||
(write-sequence (text-utils:string->octets response)
|
(write-sequence (text-utils:string->octets response)
|
||||||
stream)
|
stream)
|
||||||
(close stream)
|
(close stream)
|
||||||
(get-data)))))))))))))
|
(get-data))))))))))))))
|
||||||
(loop (get-data))))))
|
(loop (get-data))))))
|
||||||
|
|
|
@ -288,7 +288,7 @@
|
||||||
(handler-case
|
(handler-case
|
||||||
(gemini-remove-stream actual-iri)
|
(gemini-remove-stream actual-iri)
|
||||||
(error (e)
|
(error (e)
|
||||||
(debug-gemini-gui "error removing stream ~a" e)))
|
(debug-gemini-gui "error removing stream ~a: ~a" url e)))
|
||||||
(gemini-client:request-dispatch url
|
(gemini-client:request-dispatch url
|
||||||
gemini-client::dispatch-table
|
gemini-client::dispatch-table
|
||||||
:certificate certificate
|
:certificate certificate
|
||||||
|
@ -301,10 +301,13 @@
|
||||||
(format nil "~a" e)
|
(format nil "~a" e)
|
||||||
url))
|
url))
|
||||||
(conditions:not-implemented-error (e)
|
(conditions:not-implemented-error (e)
|
||||||
(error (_ "Error: ~a") e))
|
(error (_ "Error getting ~s: ~a") url e))
|
||||||
(gemini-client:gemini-protocol-error (e)
|
(gemini-client:gemini-protocol-error (e)
|
||||||
(make-gemini-response (gemini-client:error-code e)
|
(make-gemini-response (gemini-client:error-code e)
|
||||||
(gemini-client:error-description e)
|
(format nil
|
||||||
|
"~s: ~a"
|
||||||
|
url
|
||||||
|
(gemini-client:error-description e))
|
||||||
(gemini-client:meta e)
|
(gemini-client:meta e)
|
||||||
url))
|
url))
|
||||||
(error (e)
|
(error (e)
|
||||||
|
|
Loading…
Reference in New Issue