From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bozhidar Batsov Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Add support for custom user agent strings in url.el Date: Sun, 19 Jan 2014 10:15:41 +0200 Message-ID: References: <87k3dw5r44.fsf@cthulhu-p5kpl.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c329a28b4e7804f04e61c4 X-Trace: ger.gmane.org 1390119344 16753 80.91.229.3 (19 Jan 2014 08:15:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 19 Jan 2014 08:15:44 +0000 (UTC) Cc: emacs-devel To: Vibhav Pant Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jan 19 09:15:48 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 1W4nXo-0004bT-8I for ged-emacs-devel@m.gmane.org; Sun, 19 Jan 2014 09:15:48 +0100 Original-Received: from localhost ([::1]:45466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4nXn-0006EA-G2 for ged-emacs-devel@m.gmane.org; Sun, 19 Jan 2014 03:15:47 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4nXk-0006E1-7M for emacs-devel@gnu.org; Sun, 19 Jan 2014 03:15:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4nXi-0001nJ-Jc for emacs-devel@gnu.org; Sun, 19 Jan 2014 03:15:44 -0500 Original-Received: from mail-oa0-x229.google.com ([2607:f8b0:4003:c02::229]:34344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4nXi-0001n6-Cr for emacs-devel@gnu.org; Sun, 19 Jan 2014 03:15:42 -0500 Original-Received: by mail-oa0-f41.google.com with SMTP id j17so445166oag.14 for ; Sun, 19 Jan 2014 00:15:41 -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=tiJk8j7cwbCU271n5bztXjJIczghME9xyfwbtRvilZ8=; b=sZIZ7eT2QuD0+T3DsPk2pqC9+k1ipZVE5mAhB/Mt9Sk60pWCJefGJMYv8c52119cYK HbOGUfat38jRB5y3W56Hi9b23O6Iw0W0b/VE3L+n2dGdjxEWAswwamt6J6j1jj9vNeX+ 1xkXE8QYNiOFX2e6dz5SOsnVtq8hoXD5Hb1BYxh7caBKqKeqPNl9JfbN2mVGghffyo61 +6xPgDqyPsVD9at9ccPDHAufcRFCC0pnME6+JW4QOS4bew0DQ3CcZZosoOmNgzMmaOas v41ANs/3g2xyt73ySO3/MDLK2D5QrhhtF4e7Ly/xcy/LP8lI29QCOfDhtOqDkEUIXQFi j/rg== X-Received: by 10.182.114.132 with SMTP id jg4mr10108087obb.29.1390119341475; Sun, 19 Jan 2014 00:15:41 -0800 (PST) Original-Received: by 10.76.79.102 with HTTP; Sun, 19 Jan 2014 00:15:41 -0800 (PST) In-Reply-To: <87k3dw5r44.fsf@cthulhu-p5kpl.lan> X-Google-Sender-Auth: _AnNaftH9wfFjNCLK1qeJc3mhBc X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::229 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:168725 Archived-At: --001a11c329a28b4e7804f04e61c4 Content-Type: text/plain; charset=UTF-8 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. On 19 January 2014 10:10, Vibhav Pant wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA512 > > I added support to url.el for a custom user agent string by defining a > variable url-custom-user-agent which contains a user-defined string. The > variable is nil by default, in which case the function > url-http-user-agent-string reutrns the default user agent. > (Patch was created on a git repository) > > diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el > index ac2e140..1b63a25 100644 > --- a/lisp/url/url-http.el > +++ b/lisp/url/url-http.el > @@ -214,11 +214,15 @@ 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))) > + > + (if url-custom-user-agent > + (format "User-Agent: %s\n" url-custom-user-agent) > + > + (format "User-Agent: %sURL/%s\r\n" > + (if url-package-name > + (concat url-package-name "/" url-package-version " ") > + "") > + url-version)))) > > (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.el b/lisp/url/url.el > index cbbcfd4..c54a94e 100644 > --- a/lisp/url/url.el > +++ b/lisp/url/url.el > @@ -51,6 +51,10 @@ > :type 'directory > :group 'url) > > +(defvar url-custom-user-agent nil > + "User Agent used by url-http-create-request to fetch pages. If nil, > +the default user agent will be used.") > + > (defun url-do-setup () > "Setup the URL package. > This is to avoid conflict with user settings if URL is dumped with > > - -- > Vibhav Pant > vibhavp@gmail.com > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.22 (GNU/Linux) > > iQIcBAEBCgAGBQJS24fqAAoJEO86onTybWtcUdkP/2s5MGg3/zY/Xg8KmSxAU20x > Ki0UamZHp5xNgr6UcN0SIseVGTTMBfJrwWL70LnslvvzRcPysRK0v+sOL4PjNcsT > nkOU8BjsTt4HMFi48LPqhr+OacAFrMVT0E3vo0rtYoQSSw7tNgEprLUr3i2Yc1vY > II23YllVdIqb6Ys6arYuMb5V5vP83GfnV9hm1jNSt3TGefSMsgDVggBRiw7NBk8Q > pJqZ14rblX68V+b2cmw8JAzDkq7mWZ+s6CU/Ic4KI3a37k3kvoDwXwU8kCMVpP7Q > aBK9VzSLlDzzLD+TZI7I7K5n6dA4He4BwwhFgQuUwOmoI5nF3W7y1gSOCL4sBOLF > 5tqlRZFR+RJUDGabV6PoSux2K61sYegMN0NzzyrUCTPwqb9ISMNBfGfL0lp/QFuh > ENxHmTnyO/J+FTIFAQ4Dbv4RYn5xxivgPp4UmYG3vin7b3E/+2jsOKdeQO/V5iBA > 85XUKEdxH5JUergw0A9rsBvWkRw/iy89+edqg1hNJkWD8sSY+4H3QXGly63mQzdc > 51QWCwAJ1ShPif8RI9yD1Eyvctoasv+WM42NakCZ7bDUOwuHqJfAAEVbQeg9ijn9 > EynM7n5CmAAap6vrjdeNWJvxPWPXv32UHSsstOAN7MPgd9Cw6gZvfYY4DITHqWbe > BykRZe2zqv4iIlgL87Rg > =8VAL > -----END PGP SIGNATURE----- > > --001a11c329a28b4e7804f04e61c4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Seems to me that there should be just a defcustom `url-use= r-agent' and it should be used always. By default it should have whatev= er value it currently has and users will be able to customise it.


On 19 January 2014 10:10, Vibhav Pant <= vibhavp@gmail.com> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I added support to url.el for a custom user agent string by defining a
variable url-custom-user-agent which contains a user-defined string. The variable is nil by default, in which case the function
url-http-user-agent-string reutrns the default user agent.
(Patch was created on a git repository)

diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index ac2e140..1b63a25 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -214,11 +214,15 @@ request.")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (and (listp url-privacy-level)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(memq 'agent url= -privacy-level)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0""
- =C2=A0 =C2=A0(format "User-Agent: %sURL/%s\r\n"
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if url-package-name
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (concat url-package-name= "/" url-package-version " ")
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "")
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 url-version)))
+
+ =C2=A0 =C2=A0(if url-custom-user-agent
+ =C2=A0 =C2=A0 =C2=A0 (format "User-Agent: %s\n" url-custom-user= -agent)
+
+ =C2=A0 =C2=A0 =C2=A0(format "User-Agent: %sURL/%s\r\n"
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if url-package-name
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (concat url-packa= ge-name "/" url-package-version " ")
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "")
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 url-version))))

=C2=A0(defun url-http-create-request (&optional ref-url)
=C2=A0 =C2=A0"Create an HTTP request for `url-http-target-url', re= ferred to by REF-URL."
diff --git a/lisp/url/url.el b/lisp/url/url.el
index cbbcfd4..c54a94e 100644
--- a/lisp/url/url.el
+++ b/lisp/url/url.el
@@ -51,6 +51,10 @@
=C2=A0 =C2=A0:type 'directory
=C2=A0 =C2=A0:group 'url)

+(defvar url-custom-user-agent nil
+ =C2=A0"User Agent used by url-http-create-request to fetch pages. If= nil,
+the default user agent will be used.")
+
=C2=A0(defun url-do-setup ()
=C2=A0 =C2=A0"Setup the URL package.
=C2=A0This is to avoid conflict with user settings if URL is dumped with
- --
Vibhav Pant
vibhavp@gmail.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJS24fqAAoJEO86onTybWtcUdkP/2s5MGg3/zY/Xg8KmSxAU20x
Ki0UamZHp5xNgr6UcN0SIseVGTTMBfJrwWL70LnslvvzRcPysRK0v+sOL4PjNcsT
nkOU8BjsTt4HMFi48LPqhr+OacAFrMVT0E3vo0rtYoQSSw7tNgEprLUr3i2Yc1vY
II23YllVdIqb6Ys6arYuMb5V5vP83GfnV9hm1jNSt3TGefSMsgDVggBRiw7NBk8Q
pJqZ14rblX68V+b2cmw8JAzDkq7mWZ+s6CU/Ic4KI3a37k3kvoDwXwU8kCMVpP7Q
aBK9VzSLlDzzLD+TZI7I7K5n6dA4He4BwwhFgQuUwOmoI5nF3W7y1gSOCL4sBOLF
5tqlRZFR+RJUDGabV6PoSux2K61sYegMN0NzzyrUCTPwqb9ISMNBfGfL0lp/QFuh
ENxHmTnyO/J+FTIFAQ4Dbv4RYn5xxivgPp4UmYG3vin7b3E/+2jsOKdeQO/V5iBA
85XUKEdxH5JUergw0A9rsBvWkRw/iy89+edqg1hNJkWD8sSY+4H3QXGly63mQzdc
51QWCwAJ1ShPif8RI9yD1Eyvctoasv+WM42NakCZ7bDUOwuHqJfAAEVbQeg9ijn9
EynM7n5CmAAap6vrjdeNWJvxPWPXv32UHSsstOAN7MPgd9Cw6gZvfYY4DITHqWbe
BykRZe2zqv4iIlgL87Rg
=3D8VAL
-----END PGP SIGNATURE-----


--001a11c329a28b4e7804f04e61c4--