@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

HyperSpecを開くRoswellスクリプトをプロキシ環境下で動かす

blog.8arrow.org

深町さんのスクリプトを使ってみたかったが、シンボル一覧を取得するときにプロキシを超えられなかった。

drakma:http-request環境変数HTTP_PROXYの内容を渡すように変更してみた。 こんな変更でよいのかわからない。

diff --git a/clhs.ros b/clhs.ros
old mode 100644
new mode 100755
index 43b0abb..0ef9da3
--- a/clhs.ros
+++ b/clhs.ros
@@ -39,6 +39,9 @@ Environment variables
       Command name to open an URL with the default browser.
       The default value is 'open' for Mac and 'xdg-open' for Linux.
 
+    HTTP_PROXY:
+      Proxy url for fetching symbols map.
+
 
 Copyright
 ---------
@@ -104,11 +107,19 @@ This script is licensed under the MIT License.
                                    ,args))))
        ,@body)))
 
+(defun get-http-proxy ()
+  (let ((proxy (uiop:getenv "HTTP_PROXY")))
+    (if (string= proxy "")
+        nil
+      (with-package-functions :quri (uri uri-host uri-port)
+        (let ((proxy-url (uri proxy)))
+          `(,(uri-host proxy-url) ,(uri-port proxy-url)))))))
+
 (defun retrieve-url (url)
   (with-package-functions :drakma (http-request)
     (tagbody retry
        (multiple-value-bind (body status)
-           (http-request url)
+           (http-request url :proxy (get-http-proxy))
          (unless (= status 200)
            (restart-case
                (error "Failed to retrieve ~S (Code=~A)" url status)
@@ -125,7 +136,7 @@ This script is licensed under the MIT License.
   (format nil "~A~A" *clhs-base-url* path))
 
 (defun retrieve-clhs-symbols-map ()
-  (ql:quickload '(:drakma :plump :clss) :silent t)
+  (ql:quickload '(:drakma :plump :clss :quri) :silent t)
 
   (with-package-functions :plump (parse text attribute)
     (with-package-functions :clss (select)

Revisions · A Roswell script for opening HyperSpec page describing a given symbol in the default browser. · GitHub

gistのdiffは埋め込めないのか。。。

gist.github.com