diff options
author | Clément Pit--Claudel <clement.pit@gmail.com> | 2016-04-24 14:51:33 +0200 |
---|---|---|
committer | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2016-04-24 14:51:33 +0200 |
commit | 234ef3b432b7dff6629a12be5dd03a163b8e8619 (patch) | |
tree | e2aed8414502156d3801ccaaa12d06f9556be4a2 /lisp/url/url-http.el | |
parent | 97ecff0783128edeb6fe5f6e441993c9bbf2a25a (diff) | |
download | emacs-234ef3b432b7dff6629a12be5dd03a163b8e8619.tar.gz |
Compute User-Agent dynamically in url-http
* url-http.el (url-http-user-agent-string): Compute User-Agent
string dynamically.
(url-http--user-agent-default-string): New function.
* url-vars.el (url-privacy-level): Allow `emacs' in list of
information not to send.
(url-user-agent): Add nil and `default' options; do not
pre-compute value.
Diffstat (limited to 'lisp/url/url-http.el')
-rw-r--r-- | lisp/url/url-http.el | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el index 1fe9ac25555..23cd69590dc 100644 --- a/lisp/url/url-http.el +++ b/lisp/url/url-http.el @@ -222,15 +222,36 @@ request.") (if connection (url-http-mark-connection-as-busy host port connection)))) +(defun url-http--user-agent-default-string () + "Compute a default User-Agent string based on `url-privacy-level'." + (let ((package-info (when url-package-name + (format "%s/%s" url-package-name url-package-version))) + (emacs-info (unless (and (listp url-privacy-level) + (memq 'emacs url-privacy-level)) + (format "Emacs/%s" emacs-version))) + (os-info (unless (and (listp url-privacy-level) + (memq 'os url-privacy-level)) + (format "(%s; %s)" url-system-type url-os-type))) + (url-info (format "URL/%s" url-version))) + (string-join (delq nil (list package-info url-info + emacs-info os-info)) + " "))) + ;; Building an HTTP request (defun url-http-user-agent-string () - (if (or (eq url-privacy-level 'paranoid) - (and (listp url-privacy-level) - (memq 'agent url-privacy-level))) - "" - (if (functionp url-user-agent) - (funcall url-user-agent) - url-user-agent))) + "Compute a User-Agent string. +The string is based on `url-privacy-level' and `url-user-agent'." + (let* ((hide-ua + (or (eq url-privacy-level 'paranoid) + (and (listp url-privacy-level) + (memq 'agent url-privacy-level)))) + (ua-string + (and (not hide-ua) + (cond + ((functionp url-user-agent) (funcall url-user-agent)) + ((stringp url-user-agent) url-user-agent) + ((eq url-user-agent 'default) (url-http--user-agent-default-string)))))) + (if ua-string (format "User-Agent: %s\r\n" (string-trim ua-string)) ""))) (defun url-http-create-request (&optional ref-url) "Create an HTTP request for `url-http-target-url', referred to by REF-URL." |