1
0
Fork 0

- [gemini] percent encoding path query and fragment before perfoming the request.

This commit is contained in:
cage 2020-12-25 18:22:40 +01:00
parent 9fd958d12b
commit e32e025d10
1 changed files with 22 additions and 3 deletions

View File

@ -284,16 +284,35 @@
(os-utils:generate-ssl-certificate cert-dir) (os-utils:generate-ssl-certificate cert-dir)
(values certificate key)))) (values certificate key))))
(defun percent-encode-path (path)
(let ((splitted (split "/" path)))
(if splitted
(reduce (lambda (a b) (strcat a "/" (percent-encode b)))
splitted)
path)))
(defun percent-encode-allow-null (data)
(when data
(percent-encode data)))
(defun percent-encode-query (query)
(percent-encode-allow-null query))
(defun percent-encode-fragment (fragment)
(percent-encode-allow-null fragment))
(defun request (host path &key (defun request (host path &key
(query nil) (query nil)
(port +gemini-default-port+) (port +gemini-default-port+)
(fragment nil) (fragment nil)
(client-certificate nil) (client-certificate nil)
(certificate-key nil)) (certificate-key nil))
(let* ((iri (make-gemini-iri host path :query query :port port :fragment fragment)) (let* ((iri (make-gemini-iri host
(percent-encode-path path)
:query (percent-encode-query query)
:port port
: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+)))
(when query
(setf iri (strcat iri "?" (percent-encode query))))
(cl+ssl:with-global-context (ctx :auto-free-p t) (cl+ssl:with-global-context (ctx :auto-free-p t)
(let ((socket (usocket:socket-connect (idn:unicode->ascii host) (let ((socket (usocket:socket-connect (idn:unicode->ascii host)
port port