Skip to content

Commit

Permalink
Use URL library with proxy configuration for `twittering-mode'.
Browse files Browse the repository at this point in the history
* twittering-mode.el (twittering-url-wrapper): new wrapper
function for using URL library with proxy configuration for
`twittering-mode'.
(twittering-url-insert-file-contents): likewise.
(twittering-url-retrieve-synchronously): likewise.
(twittering-setup-proxy): call `url-scheme-get-property' to avoid
`url-proxy-services' to be reset.
(twittering-retrieve-image): use the wrapper function instead of
a function in URL library.
(twittering-tinyurl-get): likewise.
  • Loading branch information
cvmat committed Mar 28, 2010
1 parent 18443e2 commit 83e017d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
@@ -1,3 +1,16 @@
2010-03-29 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-url-wrapper): new wrapper
function for using URL library with proxy configuration for
`twittering-mode'.
(twittering-url-insert-file-contents): likewise.
(twittering-url-retrieve-synchronously): likewise.
(twittering-setup-proxy): call `url-scheme-get-property' to avoid
`url-proxy-services' to be reset.
(twittering-retrieve-image): use the wrapper function instead of
a function in URL library.
(twittering-tinyurl-get): likewise.

2010-03-25 Tadashi MATSUO <tad@mymail.twin.jp>

* twittering-mode.el (twittering-get-status-url): change the
Expand Down
37 changes: 33 additions & 4 deletions twittering-mode.el
Expand Up @@ -340,6 +340,14 @@ SCHEME must be \"http\" or \"https\"."
nil)))))

(defun twittering-setup-proxy ()
(when (require 'url-methods nil t)
;; If `url-scheme-registry' is not initialized,
;; `url-proxy-services' will be reset by calling
;; `url-insert-file-contents' or `url-retrieve-synchronously', etc.
;; To avoid it, initialize `url-scheme-registry' by calling
;; `url-scheme-get-property' before calling such functions.
(url-scheme-get-property "http" 'name)
(url-scheme-get-property "https" 'name))
(unless (and twittering-proxy-server twittering-proxy-port)
(let ((proxy-info (or (if twittering-use-ssl
(twittering-find-proxy "https"))
Expand Down Expand Up @@ -1651,6 +1659,28 @@ The alist consists of pairs of field-name and field-value, such as
(twittering-tinyurl-replace-at-point)
(twittering-edit-length-check)))

;;;
;;; Functions for URL library
;;;

(defun twittering-url-wrapper (func &rest args)
(let ((url-proxy-services
(when twittering-proxy-use
(let ((proxy-str (format "%s:%s" twittering-proxy-server
twittering-proxy-port)))
(if twittering-use-ssl
`(("http" . ,proxy-str)
("https" . ,proxy-str))
`(("http" . ,proxy-str))))))
(url-show-status nil))
(apply func args)))

(defun twittering-url-insert-file-contents (url)
(twittering-url-wrapper 'url-insert-file-contents url))

(defun twittering-url-retrieve-synchronously (url)
(twittering-url-wrapper 'url-retrieve-synchronously url))

;;;
;;; Basic HTTP functions
;;;
Expand Down Expand Up @@ -3412,9 +3442,8 @@ variable `twittering-status-format'."
(set-buffer-multibyte nil)
(let ((coding-system-for-read 'binary)
(coding-system-for-write 'binary)
(url-show-status nil)
(require-final-newline nil))
(url-insert-file-contents image-url)
(twittering-url-insert-file-contents image-url)
(let ((image-type (twittering-image-type image-url (current-buffer))))
(and twittering-use-convert
(or (not (image-type-available-p image-type))
Expand Down Expand Up @@ -3459,8 +3488,8 @@ variable `twittering-status-format'."
(symbol-name (car x)))
twittering-tinyurl-services-map ", ")))
(if longurl
(let* ((url-show-status nil)
(buffer (url-retrieve-synchronously (concat api longurl))))
(let ((buffer
(twittering-url-retrieve-synchronously (concat api longurl))))
(with-current-buffer buffer
(goto-char (point-min))
(prog1
Expand Down

0 comments on commit 83e017d

Please sign in to comment.