diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2017-01-21 20:00:04 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2017-01-21 20:00:04 +0100 |
commit | 42354bb6012d61c359207faa795885191f5088f2 (patch) | |
tree | 871be3d0e9fdf3fc24aa281ca481f323bcab9bd1 /lisp/url/with-url.el | |
parent | 688b20a289f4754b41d2dd9ae44ac69cffecf14b (diff) | |
download | emacs-42354bb6012d61c359207faa795885191f5088f2.tar.gz |
Implement ftp: and file:
Diffstat (limited to 'lisp/url/with-url.el')
-rw-r--r-- | lisp/url/with-url.el | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lisp/url/with-url.el b/lisp/url/with-url.el index da28ee66e28..17b1a16d88e 100644 --- a/lisp/url/with-url.el +++ b/lisp/url/with-url.el @@ -201,6 +201,12 @@ If given, return the value in BUFFER instead." (setf (url-request-url req) (url-request-original-url req))) (setf (url-request-parsed-url req) (url-generic-parse-url (url-request-url req))) + (pcase (url-type (url-request-parsed-url req)) + ((or "http" "https") (with-url--fetch-http req)) + ("ftp" (with-url--fetch-ftp req)) + ("file" (with-url--fetch-file req)))) + +(defun with-url--fetch-http (req) (when (or (url-request-timeout req) (url-request-read-timeout req)) (setf (url-request-timer req) @@ -232,6 +238,39 @@ If given, return the value in BUFFER instead." :filter #'with-url--filter))) (setf (url-request-process req) process)))) +(defun with-url--fetch-ftp (req) + (let ((parsed (url-request-parsed-url req))) + ;; Transform the URL into Tramp syntax and let it worry about it. + (with-url--fetch-file + (concat "/" + (and (url-user parsed) + (format "%s@" (url-user parsed))) + (url-host) + (and (url-port parsed) + (format "#s" (url-port parsed))) + ":" + (url-filename parsed))))) + +(defun with-url--fetch-file (req) + (with-current-buffer (generate-new-buffer "*request*") + (set-buffer-multibyte nil) + (let ((coding-system-for-read 'binary) + (coding-system-for-write 'binary) + (buffer (current-buffer))) + (condition-case err + (insert-file-contents-literally + (url-filename (url-request-parsed-url req))) + (error + (setq-local with-url--status + (list 500 (format "Error occurred while fetching file: %s" + err))))) + (when (or (not (url-request-ignore-errors req)) + (url-okp)) + (goto-char (point-min)) + (unwind-protect + (funcall (url-request-callback req)) + (kill-buffer buffer)))))) + (defun with-url--timer (req) (let ((now (float-time))) ;; There are two possible timeouts: One for the overall time of |