From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= Newsgroups: gmane.emacs.devel Subject: Re: Help understanding the URL code Date: Thu, 7 Apr 2016 18:00:02 +0100 Message-ID: <57069212.6030701@gmail.com> References: <5703DBB2.1030903@gmail.com> <57063E60.4040408@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="B89X5O2EdHidBxUSvLRE9x9gkFCFxQ7tt" X-Trace: ger.gmane.org 1460048615 23434 80.91.229.3 (7 Apr 2016 17:03:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 Apr 2016 17:03:35 +0000 (UTC) Cc: Emacs developers To: Lars Magne Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Apr 07 19:03:29 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aoDL4-0004xg-Se for ged-emacs-devel@m.gmane.org; Thu, 07 Apr 2016 19:03:27 +0200 Original-Received: from localhost ([::1]:51554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoDL4-0003vA-EH for ged-emacs-devel@m.gmane.org; Thu, 07 Apr 2016 13:03:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoDHx-0005Qn-HE for emacs-devel@gnu.org; Thu, 07 Apr 2016 13:00:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoDHu-0004Kt-5K for emacs-devel@gnu.org; Thu, 07 Apr 2016 13:00:13 -0400 Original-Received: from mout.kundenserver.de ([217.72.192.75]:58500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoDHt-0004KU-T4 for emacs-devel@gnu.org; Thu, 07 Apr 2016 13:00:10 -0400 Original-Received: from [172.16.0.124] ([87.82.210.162]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0LZl8O-1bXDkq3Pgq-00lUum; Thu, 07 Apr 2016 19:00:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: X-Provags-ID: V03:K0:RfoHUtcMg/yn53S9S7HLAF9dV6W8YSlY1m5Za91culdGZ5O3ccT IsSCdBkBWs04tTerUhaY1YG2u9zZe/Is/wMYnOtNNMLRdKTgZyvyHYxNnXq5UJnzC0uuAgL io835cikQbOoKUJtnr03L3+ryRjaByB/HOX/MhtuqRxTGtEC/9lV2te9qcAIarXhTMZQobr TSKDrNJVDB0vTm7creplA== X-UI-Out-Filterresults: notjunk:1;V01:K0:r+r3Fbugr/0=:WDDOwqvWyoj3Z8Dc2sCf2c 0/5QgA4tUZ0lYlMpr72Fr+wR7xCGApWsjB8+/fD/FugeH2THNxiVLtVlLBmG6nXYI3tGnqrbv UL6F0P+QQZ9lP4LHF/SGZw57VGyf5vNwfdeiMEubTNB3ZQ9OXqZDKA6hn5+hy38c4mGXKoG9Q TnGwpxaD8lU11HsQJlksO3xXyDTuFLNVHs0ejs6Tzzmi6OP3RVW5L20KSMAolq0NNWiUK68RF SI+rLFWMOAPUAt9IT5oBeqik0z4sV1ZhlISpkA1kmtTPkPMAfdmhyhVhndqC+G+5RzyBHyBch 75BdBlRVSz3VnoqWIgRudafh8SZHHFvIIt0nShX7O/oO+qtltBuoKYjqowalYQ92l7+XF/Ugh V96/x7ZmtNwbCIDNYeFVaR+1pnoLmH3hbuCOsDdsf3EAWupGKezZjMAX5XuKZfsS0pUYRS+2p tpcJHMG2kT9xWGIWyo7NzI8cMqkNpSsKgSMm0rr+BjQ414Q4mtleIM7jZHjoPp344BgxSk9vP 04naezn6XRvLMYghMFp5mq3ZOWDBPl6posRtA9wII/OuySW4jfhkG5SywbQZz5OJG6wDE6qk5 1+tH217pjL9QZbKPkC56KLPw5VTNnTt7cQxHaZZ5/aFngeWEwdeEqKHvGbZGIWxEbDKDWtaqv q6THwSUNwsNNE6PB3+ZqBqRpH2m46Pzj7L7N4OjWimKOkf582NXB1Prk558RiKpaRlDY= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.75 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:202805 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --B89X5O2EdHidBxUSvLRE9x9gkFCFxQ7tt Content-Type: multipart/mixed; boundary="2vIhwNsIfHmXOBICFf4pmhB5tk5JlWmN3" From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= To: Lars Magne Ingebrigtsen Cc: Emacs developers Message-ID: <57069212.6030701@gmail.com> Subject: Re: Help understanding the URL code References: <5703DBB2.1030903@gmail.com> <57063E60.4040408@gmail.com> In-Reply-To: --2vIhwNsIfHmXOBICFf4pmhB5tk5JlWmN3 Content-Type: multipart/mixed; boundary="------------080909030209060601000206" This is a multi-part message in MIME format. --------------080909030209060601000206 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 04/07/2016 01:32 PM, Lars Magne Ingebrigtsen wrote: > Looks good, I think. One little niggle: >=20 > [...] >=20 >> + (format "GNUEmacs/%s" emacs-version))) >=20 > I think "Emacs" is better here. "GNUEmacs" looks very odd to me. Thanks! Here is an updated patch. Cheers, Cl=E9ment. --------------080909030209060601000206 Content-Type: text/x-diff; name="0001-Take-Emacs-and-package-versions-into-account-in-URL-.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Take-Emacs-and-package-versions-into-account-in-URL-.pa"; filename*1="tch" =46rom 38849b1b513a51ffd754c3764b650c0c3428a173 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Cl=3DC3=3DA9ment=3D20Pit--Claudel?=3D Date: Thu, 7 Apr 2016 11:31:13 +0100 Subject: [PATCH] Take Emacs and package versions into account in URL's User-Agent string * 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. * url-http.el (url-http-user-agent-string): Compute User-Agent string dynamically. (url-http--user-agent-default-string): New function. The original code took `url-package-name' and `url-package-version' into account only when url-vars.el was loaded; the new code takes them into account in all cases, allowing users to let-bind them. It also adds the current Emacs version to the User-Agent string. --- lisp/url/url-http.el | 35 ++++++++++++++++++++++++++++------- lisp/url/url-vars.el | 25 ++++++++++++++++--------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el index 5832e92..9077e62 100644 --- a/lisp/url/url-http.el +++ b/lisp/url/url-http.el @@ -211,15 +211,36 @@ url-http-find-free-connection (if connection (url-http-mark-connection-as-busy host port connection)))) =20 +(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-ver= sion))) + (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-defa= ult-string)))))) + (if ua-string (format "User-Agent: %s\r\n" (string-trim ua-string)) = ""))) =20 (defun url-http-create-request (&optional ref-url) "Create an HTTP request for `url-http-target-url', referred to by REF-= URL." diff --git a/lisp/url/url-vars.el b/lisp/url/url-vars.el index 960a04a..97dac9c 100644 --- a/lisp/url/url-vars.el +++ b/lisp/url/url-vars.el @@ -116,6 +116,7 @@ url-privacy-level Valid symbols are: email -- the email address os -- the operating system info +emacs -- the version of Emacs lastloc -- the last location agent -- do not send the User-Agent string cookies -- never accept HTTP cookies @@ -143,6 +144,7 @@ url-privacy-level (checklist :tag "Custom" (const :tag "Email address" :value email) (const :tag "Operating system" :value os) + (const :tag "Emacs version" :value emacs) (const :tag "Last location" :value lastloc) (const :tag "Browser identification" :value agent) (const :tag "No cookies" :value cookie))) @@ -357,15 +359,20 @@ url-gateway-method (const :tag "Direct connection" :value native)) :group 'url-hairy) =20 -(defcustom url-user-agent (format "User-Agent: %sURL/%s\r\n" - (if url-package-name - (concat url-package-name "/" - url-package-version " ") - "") url-version) - "User Agent used by the URL package for HTTP/HTTPS requests -Should be a string or a function of no arguments returning a string." - :type '(choice (string :tag "A static User-Agent string") - (function :tag "Call a function to get the User-Agent s= tring")) +(defcustom url-user-agent 'default + "User Agent used by the URL package for HTTP/HTTPS requests. +Should be one of: +* A string (not including the \"User-Agent:\" prefix) +* A function of no arguments, returning a string +* `default' (to compute a value according to `url-privacy-level') +* nil (to omit the User-Agent header entirely)" + :type + '(choice + (string :tag "A static User-Agent string") + (function :tag "Call a function to get the User-Agent string") + (const :tag "No User-Agent at all" :value nil) + (const :tag "An string auto-generated according to `url-privacy-leve= l'" + :value default)) :version "25.1" :group 'url) =20 --=20 2.8.1 --------------080909030209060601000206-- --2vIhwNsIfHmXOBICFf4pmhB5tk5JlWmN3-- --B89X5O2EdHidBxUSvLRE9x9gkFCFxQ7tt Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJXBpIYAAoJEPqg+cTm90wj7H0P/RVChTsycZMFMGmlcorfVdmS 0Agd06k6Jg96rL1NfjRzH9qu3D8OaP0/YKxL5gf7KWiSLFAcVkn4oUmAtZ1Pxap9 wtwnWOiKCkPBkwn6V62XCXkNapvI9HRtpFY5EJ2k/Io/q8EOMmjmixD6bSrpqJf1 aSHVQQTnfw+bAGyaW7rzCQ7S+K8c/JTjx8+dWyaDQBVn/l8jqPUV9ElzDo2wUjeO TdI4IkVpksisxjd+52e6prYA5ml+4ecH9sCTYmf6xBMzXdl+FGvUYYsH8u395Suj V8k+cinDU0mkHp6HaSzmHJQgX6t+fpoQyXPN7QUNGbdlQnyJfQ7aVaqS1XuzNtUw gjuRwd0+3UQn33f614fdYmhM/0zGacxK6j9tHyKKEesskrk0AEgPtNoLD7uURSy6 bE0LMEZGG3FLDsz/6w6K7w4a11jA31mJTeoZtJQyTMo5PYvgH02vc8/+d8MFfpqG bVgoH/HOz/tYZ30+svo4vu9Dk7mhwHUxAPa+keuirVpAaGWbQ0skam71C6dLZIvm xFwa0ZfbEqPaTniHI0rvUep13eAsTRy823SfY8dTJ6NV/+6nj/J1uZbttFjZAyfI NaEUcQtbKZ8LwNPAuMjUtNaoeLyBLbmGSU9Bre+eO6C6xHzlZDuVV1Z3bBemI1es lGg/w/eJn2Q8LOP8V+rc =NbQz -----END PGP SIGNATURE----- --B89X5O2EdHidBxUSvLRE9x9gkFCFxQ7tt--