From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Vibhav Pant Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Add support for custom user agent strings in url.el Date: Sun, 19 Jan 2014 15:28:45 +0530 Message-ID: References: <87k3dw5r44.fsf@cthulhu-p5kpl.lan> <87iotg5pw5.fsf@cthulhu-p5kpl.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b6773d61f11a804f04fd280 X-Trace: ger.gmane.org 1390125525 8880 80.91.229.3 (19 Jan 2014 09:58:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 19 Jan 2014 09:58:45 +0000 (UTC) Cc: emacs-devel To: Bozhidar Batsov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jan 19 10:58:53 2014 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 1W4p9X-0000e7-Vt for ged-emacs-devel@m.gmane.org; Sun, 19 Jan 2014 10:58:52 +0100 Original-Received: from localhost ([::1]:45646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4p9X-0005E7-Kj for ged-emacs-devel@m.gmane.org; Sun, 19 Jan 2014 04:58:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4p9U-0005Dr-8H for emacs-devel@gnu.org; Sun, 19 Jan 2014 04:58:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4p9S-0003J4-QD for emacs-devel@gnu.org; Sun, 19 Jan 2014 04:58:48 -0500 Original-Received: from mail-pb0-x236.google.com ([2607:f8b0:400e:c01::236]:37879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4p9S-0003Iz-Cp for emacs-devel@gnu.org; Sun, 19 Jan 2014 04:58:46 -0500 Original-Received: by mail-pb0-f54.google.com with SMTP id uo5so2186906pbc.41 for ; Sun, 19 Jan 2014 01:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=zaj0o1w16uPgHDR3GOp0xKNAlEBqMQodBM7nag9rne4=; b=LkEisG2an8Y5P+ONNU9KNJlYYdVFBTypDvJoUns970wO2pu5mxkP+Unsd5JxgUU1JB 52ipsaWdI3vfwj1rS63Wx0wz9WURD1mqzA5KG2AZ+CvThP7YFxPUCAFTJewLP5PVTRAT ZEYC69F3/V9/9A8CphsuUYdXwW8jeX3cpgyeit/bAiXZXRb5zjUtrj54uGRPVOqvOkzc lYMkbRsRI7yWxLlYn1JH0VwoV62SSIkl8tpaQEZ8jMkLprbmI7cho6AEyVXKzDDU5k9p lodTfBrJm8EnG3eeA2CkPIm4BN3IxA2/xlBViNh5Rc7RQ0x2dbedTj+fe8kXrfarv2yY k6mA== X-Received: by 10.68.91.3 with SMTP id ca3mr12363394pbb.20.1390125525175; Sun, 19 Jan 2014 01:58:45 -0800 (PST) Original-Received: by 10.70.70.231 with HTTP; Sun, 19 Jan 2014 01:58:45 -0800 (PST) In-Reply-To: X-Google-Sender-Auth: JXNEbOwsv7YZbiMTaIh2_8Eaw4g X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::236 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:168729 Archived-At: --047d7b6773d61f11a804f04fd280 Content-Type: text/plain; charset=ISO-8859-1 By the way, the patch will still respect the paranoid option, where no user agent string is sent. On Sun, Jan 19, 2014 at 3:15 PM, Vibhav Pant wrote: > Here's the fixed patch. I created a defcustom for the user-agent in > url-http.el. > > diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el > index ac2e140..6a0ec13 100644 > --- a/lisp/url/url-http.el > +++ b/lisp/url/url-http.el > @@ -132,6 +132,15 @@ request.") > (507 insufficient-storage "Insufficient storage")) > "The HTTP return codes and their text.") > > +(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." > + :type 'string > + :group 'url) > + > ;(eval-when-compile > ;; These are all macros so that they are hidden from external sight > ;; when the file is byte-compiled. > @@ -214,11 +223,7 @@ request.") > > (and (listp url-privacy-level) > (memq 'agent url-privacy-level))) > "" > - (format "User-Agent: %sURL/%s\r\n" > - (if url-package-name > - (concat url-package-name "/" url-package-version " ") > - "") > - url-version))) > + url-user-agent)) > > > (defun url-http-create-request (&optional ref-url) > "Create an HTTP request for `url-http-target-url', referred to by > REF-URL." > > > > On Sun, Jan 19, 2014 at 2:42 PM, Bozhidar Batsov wrote: > >> The default of the defcustom can also be the result of a function call >> (like `format', etc). Basically everything that returns a string will do. >> >> >> On 19 January 2014 10:36, Vibhav Pant wrote: >> >>> >>> Bozhidar Batsov writes: >>> >>> > Seems to me that there should be just a defcustom `url-user-agent' and >>> it >>> > should be used always. By default it should have whatever value it >>> > currently has and users will be able to customise it. >>> The function url-http-user-agent-string generates a user agent by >>> concatinating url-package-name and url-package-version. So the defcustom >>> would have to be a function or a sexp, making things a little confusing >>> for new users. >>> >>> -- >>> Vibhav Pant >>> vibhavp@gmail.com >>> >> >> > > > -- > Vibhav Pant > vibhavp@gmail.com > -- Vibhav Pant vibhavp@ubuntu.com "0x2B | ~ 0x2B (Hamlet, Shakespeare)" --047d7b6773d61f11a804f04fd280 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
By the way, the patch will still respect the paranoid opti= on, where no user agent string is sent.


On Sun, Jan 19, 2014 at 3:15 PM, Vibhav= Pant <vibhavp@ubuntu.com> wrote:
Here's the fixed patch.= I created a defcustom for the user-agent in url-http.el.

diff --git= a/lisp/url/url-http.el b/lisp/url/url-http.el
index ac2e140..6a0ec13 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -132,6 +132,15 @@ request.")
=A0= =A0=A0=A0 (507 insufficient-storage=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "= Insufficient storage"))
=A0=A0 "The HTTP return codes and thei= r text.")
=A0
+(defcustom url-user-agent (format "User-Agen= t: %sURL/%s\r\n"

+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 (if url-package-name
+=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (concat url-package-name "/"
+=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 url-package-version " "= ;)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "") url-version)
+=A0 "Use= r Agent used by the URL package."
+=A0 :type 'string
+=A0 :g= roup 'url)
+
=A0;(eval-when-compile
=A0;; These are all macros= so that they are hidden from external sight
=A0;; when the file is byte-compiled.
@@ -214,11 +223,7 @@ request."= ;)

=A0=A0=A0=A0=A0=A0=A0=A0=A0 (and (listp url-privacy= -level)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (memq 'agent url-= privacy-level)))
=A0=A0=A0=A0=A0=A0 ""
-=A0=A0=A0 (format &= quot;User-Agent: %sURL/%s\r\n"
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (if url-package-name
-=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 (concat url-package-name "/" url-package= -version " ")
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 "&quo= t;)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 url-version)))
+=A0=A0=A0 u= rl-user-agent))

=A0
=A0(defun url-http-create-request (&optional ref-url)
=A0=A0 "Create an HTTP request for `url-http-target-url', referred= to by REF-URL."



On Sun, Jan 19, 2014 at 2:42 P= M, Bozhidar Batsov <bozhidar@batsov.com> wrote:
The default of the defcusto= m can also be the result of a function call (like `format', etc). Basic= ally everything that returns a string will do.=A0


On 19 January 2014 10:36, Vibhav Pant <vibhavp@gmail.com> wr= ote:

Bozhidar Batsov writes:

> Seems to me that there should be just a defcustom `url-user-agent'= and it
> should be used always. By default it should have whatever value it
> currently has and users will be able to customise it.
The function url-http-user-agent-string generates a user agent by
concatinating url-package-name and url-package-version. So the defcustom would have to be a function or a sexp, making things a little confusing
for new users.

--
Vibhav Pant
vibhavp@gmail.com




--
Vibhav Pan= t



--
Vibhav= Pant
vibhavp@ub= untu.com
"0x2B | ~ 0x2B (Hamlet, Shakespeare)"

--047d7b6773d61f11a804f04fd280--