unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Help understanding the URL code
@ 2016-04-05 15:37 Clément Pit--Claudel
  2016-04-05 16:54 ` Andreas Schwab
  2016-04-06 11:34 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 20+ messages in thread
From: Clément Pit--Claudel @ 2016-04-05 15:37 UTC (permalink / raw)
  To: Emacs developers


[-- Attachment #1.1.1: Type: text/plain, Size: 1729 bytes --]

Hi emacs-devel,

I'm looking into producing a patch to make it easier to customize the user-agent string that URL uses, but I'm hitting a number of walls. For example, what does this piece of code achieve?

    (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 string"))
      :version "25.1"
      :group 'url)

This defcustom is evaluated the first time that url-vars.el is loaded, right? In that case, what's the point of the url-package-name and url-package-version variables? It seems that rebinding them won't ever do anything, since the definition is evaluated once and for all. Thus IIUC this bit of code will return different values depending on whether the url package had already been loaded before or whether it was loaded through url-retrieve-synchronously being autoloaded. Is that right?

    (let ((url-package-name "MyPackage"))
      (url-retrieve-synchronously "http://example.com")
      url-user-agent)

If that's correct, then the attached (draft) patch might help in fixing this issue.

I would also welcome help on other issues, such as #23140 (about being unable to let-bind url-mime-accept-string). Am I missing something in how these new parts of url.el are supposed to be used? 

Clément.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: user-agent.patch --]
[-- Type: text/x-diff; name="user-agent.patch", Size: 3528 bytes --]

diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 5832e92..f775e72 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -211,15 +211,33 @@ url-http-find-free-connection
     (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 "GNUEmacs/%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)))
+    (format "User-Agent: %s\r\n"
+            (string-trim
+             (cond
+              ((functionp url-user-agent) (funcall url-user-agent))
+              ((stringp url-user-agent) url-user-agent)
+              (t (url-http--user-agent-default-string)))))))
 
 (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..48a4cbe 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,13 +359,11 @@ url-gateway-method
 		(const :tag "Direct connection" :value native))
   :group 'url-hairy)
 
-(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."
+(defcustom url-user-agent nil
+  "User Agent used by the URL package for HTTP/HTTPS requests.
+Should be a string not including the \"User-Agent:\", or a
+function of no arguments returning a such string.
+If nil, the value is calculated based on `url-privacy-level'."
   :type '(choice (string :tag "A static User-Agent string")
                  (function :tag "Call a function to get the User-Agent string"))
   :version "25.1"

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-05 15:37 Help understanding the URL code Clément Pit--Claudel
@ 2016-04-05 16:54 ` Andreas Schwab
  2016-04-06 11:34 ` Lars Magne Ingebrigtsen
  1 sibling, 0 replies; 20+ messages in thread
From: Andreas Schwab @ 2016-04-05 16:54 UTC (permalink / raw)
  To: Clément Pit--Claudel; +Cc: Emacs developers

Clément Pit--Claudel <clement.pit@gmail.com> writes:

> +(defcustom url-user-agent nil
> +  "User Agent used by the URL package for HTTP/HTTPS requests.
> +Should be a string not including the \"User-Agent:\", or a
> +function of no arguments returning a such string.
> +If nil, the value is calculated based on `url-privacy-level'."
>    :type '(choice (string :tag "A static User-Agent string")
>                   (function :tag "Call a function to get the User-Agent string"))

Don't forget to update the :type.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-05 15:37 Help understanding the URL code Clément Pit--Claudel
  2016-04-05 16:54 ` Andreas Schwab
@ 2016-04-06 11:34 ` Lars Magne Ingebrigtsen
  2016-04-07 11:02   ` Clément Pit--Claudel
  1 sibling, 1 reply; 20+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-04-06 11:34 UTC (permalink / raw)
  To: Clément Pit--Claudel; +Cc: Emacs developers

Clément Pit--Claudel <clement.pit@gmail.com> writes:

> Thus IIUC this bit of code will return different values depending on
> whether the url package had already been loaded before or whether it
> was loaded through url-retrieve-synchronously being autoloaded. Is
> that right?

Yes, you're right, and that doesn't make much sense.

Your patch looks good, but perhaps this part could be changed a bit:

[...]

> +    (format "User-Agent: %s\r\n"
> +            (string-trim
> +             (cond
> +              ((functionp url-user-agent) (funcall url-user-agent))
> +              ((stringp url-user-agent) url-user-agent)
> +              (t (url-http--user-agent-default-string)))))))

It should be possible to not have a User-Agent header at all.  nil as a
value to `url-user-agent' would be the obvious choice, and `default'
could be the value to signal using `url-http--user-agent-default-string'.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-06 11:34 ` Lars Magne Ingebrigtsen
@ 2016-04-07 11:02   ` Clément Pit--Claudel
  2016-04-07 12:32     ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 20+ messages in thread
From: Clément Pit--Claudel @ 2016-04-07 11:02 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: Emacs developers


[-- Attachment #1.1.1: Type: text/plain, Size: 676 bytes --]

Hi Lars,

On 04/06/2016 12:34 PM, Lars Magne Ingebrigtsen wrote:
> Your patch looks good

Thanks for the review!

> but perhaps this part could be changed a bit:
> (...)
> It should be possible to not have a User-Agent header at all.  nil as a
> value to `url-user-agent' would be the obvious choice, and `default'
> could be the value to signal using `url-http--user-agent-default-string'.

You're right; it doesn't hurt to have that option locally too, in addition to tweaking the privacy level.

Please find an updated patch attached :) (I would also welcome comments about the commit message format; should I link to this discussion?)

Cheers,
Clément.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-Take-Emacs-and-package-versions-into-account-in-URL-.patch --]
[-- Type: text/x-diff; name="0001-Take-Emacs-and-package-versions-into-account-in-URL-.patch", Size: 5349 bytes --]

From 7552bcd037f5f2b8ce080be73adc5209e4a4fb28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit--Claudel?= <clement.pitclaudel@live.com>
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..4bdd3b5 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))))
 
+(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 "GNUEmacs/%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."
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)
 
-(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 string"))
+(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-level'"
+           :value default))
   :version "25.1"
   :group 'url)
 
-- 
2.8.1


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 11:02   ` Clément Pit--Claudel
@ 2016-04-07 12:32     ` Lars Magne Ingebrigtsen
  2016-04-07 12:53       ` Andreas Schwab
  2016-04-07 17:00       ` Clément Pit--Claudel
  0 siblings, 2 replies; 20+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-04-07 12:32 UTC (permalink / raw)
  To: Clément Pit--Claudel; +Cc: Emacs developers

Clément Pit--Claudel <clement.pit@gmail.com> writes:

> 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.

Looks good, I think.  One little niggle:

[...]

> +                      (format "GNUEmacs/%s" emacs-version)))

I think "Emacs" is better here.  "GNUEmacs" looks very odd to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 12:32     ` Lars Magne Ingebrigtsen
@ 2016-04-07 12:53       ` Andreas Schwab
  2016-04-07 13:01         ` Lars Magne Ingebrigtsen
                           ` (2 more replies)
  2016-04-07 17:00       ` Clément Pit--Claudel
  1 sibling, 3 replies; 20+ messages in thread
From: Andreas Schwab @ 2016-04-07 12:53 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: Clément Pit--Claudel, Emacs developers

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

>> +                      (format "GNUEmacs/%s" emacs-version)))
>
> I think "Emacs" is better here.  "GNUEmacs" looks very odd to me.

How about GNU/Emacs/%s?

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 12:53       ` Andreas Schwab
@ 2016-04-07 13:01         ` Lars Magne Ingebrigtsen
  2016-04-07 13:02         ` Yuri Khan
  2016-04-07 13:07         ` Stefan Monnier
  2 siblings, 0 replies; 20+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-04-07 13:01 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Clément Pit--Claudel, Emacs developers

Andreas Schwab <schwab@suse.de> writes:

> Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
>
>>> +                      (format "GNUEmacs/%s" emacs-version)))
>>
>> I think "Emacs" is better here.  "GNUEmacs" looks very odd to me.
>
> How about GNU/Emacs/%s?

That would be invalid syntax.  The tokens are supposed to be
"thing/version".

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 12:53       ` Andreas Schwab
  2016-04-07 13:01         ` Lars Magne Ingebrigtsen
@ 2016-04-07 13:02         ` Yuri Khan
  2016-04-07 13:13           ` Andreas Schwab
  2016-04-07 13:07         ` Stefan Monnier
  2 siblings, 1 reply; 20+ messages in thread
From: Yuri Khan @ 2016-04-07 13:02 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Lars Magne Ingebrigtsen, Clément Pit--Claudel,
	Emacs developers

On Thu, Apr 7, 2016 at 6:53 PM, Andreas Schwab <schwab@suse.de> wrote:

> How about GNU/Emacs/%s?

That would violate the HTTP spec for the User-Agent header (RFC 7231 §
5.5.3, RFC 7230 § 3.2.6):

     User-Agent = product *( RWS ( product / comment ) )
     product         = token ["/" product-version]
     product-version = token

     token          = 1*tchar

     tchar          = "!" / "#" / "$" / "%" / "&" / "'" / "*"
                    / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
                    / DIGIT / ALPHA
                    ; any VCHAR, except delimiters



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 12:53       ` Andreas Schwab
  2016-04-07 13:01         ` Lars Magne Ingebrigtsen
  2016-04-07 13:02         ` Yuri Khan
@ 2016-04-07 13:07         ` Stefan Monnier
  2016-04-07 14:20           ` Drew Adams
  2 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2016-04-07 13:07 UTC (permalink / raw)
  To: emacs-devel

>>> +                      (format "GNUEmacs/%s" emacs-version)))
>> I think "Emacs" is better here.  "GNUEmacs" looks very odd to me.
> How about GNU/Emacs/%s?

Why.  The product's name is "Emacs".  I don't know of any other software
whose name is Emacs, so it's unambiguous.


        Stefan




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 13:02         ` Yuri Khan
@ 2016-04-07 13:13           ` Andreas Schwab
  2016-04-07 13:22             ` Stefan Monnier
  0 siblings, 1 reply; 20+ messages in thread
From: Andreas Schwab @ 2016-04-07 13:13 UTC (permalink / raw)
  To: Yuri Khan
  Cc: Lars Magne Ingebrigtsen, Clément Pit--Claudel,
	Emacs developers

Yuri Khan <yuri.v.khan@gmail.com> writes:

> On Thu, Apr 7, 2016 at 6:53 PM, Andreas Schwab <schwab@suse.de> wrote:
>
>> How about GNU/Emacs/%s?
>
> That would violate the HTTP spec for the User-Agent header

But GNU-Emacs/%s wouldn't.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 13:13           ` Andreas Schwab
@ 2016-04-07 13:22             ` Stefan Monnier
  2016-04-07 13:32               ` Andreas Schwab
  2016-04-07 16:28               ` John Wiegley
  0 siblings, 2 replies; 20+ messages in thread
From: Stefan Monnier @ 2016-04-07 13:22 UTC (permalink / raw)
  To: emacs-devel

>> On Thu, Apr 7, 2016 at 6:53 PM, Andreas Schwab <schwab@suse.de> wrote:
>>> How about GNU/Emacs/%s?
>> That would violate the HTTP spec for the User-Agent header
> But GNU-Emacs/%s wouldn't.

But our software's name is not "GNU-Emacs", it's "Emacs" (and it's not
"GNU Emacs" either, AFAIC).


        Stefan




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 13:22             ` Stefan Monnier
@ 2016-04-07 13:32               ` Andreas Schwab
  2016-04-07 14:17                 ` Stefan Monnier
  2016-04-07 16:28               ` John Wiegley
  1 sibling, 1 reply; 20+ messages in thread
From: Andreas Schwab @ 2016-04-07 13:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> (and it's not "GNU Emacs" either, AFAIC).

RTFM.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 13:32               ` Andreas Schwab
@ 2016-04-07 14:17                 ` Stefan Monnier
  2016-04-07 14:28                   ` Andreas Schwab
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2016-04-07 14:17 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: emacs-devel

>> (and it's not "GNU Emacs" either, AFAIC).
> RTFM.

Doesn't impress me.


        Stefan



^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: Help understanding the URL code
  2016-04-07 13:07         ` Stefan Monnier
@ 2016-04-07 14:20           ` Drew Adams
  2016-04-07 21:18             ` Richard Stallman
  0 siblings, 1 reply; 20+ messages in thread
From: Drew Adams @ 2016-04-07 14:20 UTC (permalink / raw)
  To: Stefan Monnier, emacs-devel

> Why.  The product's name is "Emacs".  I don't know of any other
> software whose name is Emacs, so it's unambiguous.

There have been, and perhaps still are, other flavors of Emacs,
besides GNU Emacs.  Emacs predates the creation of GNU.

> But our software's name is not "GNU-Emacs", it's "Emacs" (and
> it's not "GNU Emacs" either, AFAIC).

Really?  To me it is "GNU Emacs".  It is the GNU flavor of Emacs.
Anything else would be misleading, IMO, if not presumptuous.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 14:17                 ` Stefan Monnier
@ 2016-04-07 14:28                   ` Andreas Schwab
  2016-04-07 15:37                     ` Stefan Monnier
  0 siblings, 1 reply; 20+ messages in thread
From: Andreas Schwab @ 2016-04-07 14:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> (and it's not "GNU Emacs" either, AFAIC).
>> RTFM.
>
> Doesn't impress me.

What's your problem with GNU?

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 14:28                   ` Andreas Schwab
@ 2016-04-07 15:37                     ` Stefan Monnier
  0 siblings, 0 replies; 20+ messages in thread
From: Stefan Monnier @ 2016-04-07 15:37 UTC (permalink / raw)
  To: emacs-devel

>>>> (and it's not "GNU Emacs" either, AFAIC).
>>> RTFM.
>> Doesn't impress me.
> What's your problem with GNU?

Nothing, I love the GNU project.  But this program's name is "Emacs"
(and it is resolutely part of the GNU project, obviously).


        Stefan




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 13:22             ` Stefan Monnier
  2016-04-07 13:32               ` Andreas Schwab
@ 2016-04-07 16:28               ` John Wiegley
  1 sibling, 0 replies; 20+ messages in thread
From: John Wiegley @ 2016-04-07 16:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 440 bytes --]

>>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:

> But our software's name is not "GNU-Emacs", it's "Emacs" (and it's not "GNU
> Emacs" either, AFAIC).

We are GNU Emacs, as in the title page to the Elisp ref manual I'm looking at:

  "GNU Emacs Lisp Reference Manual"

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 629 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 12:32     ` Lars Magne Ingebrigtsen
  2016-04-07 12:53       ` Andreas Schwab
@ 2016-04-07 17:00       ` Clément Pit--Claudel
  2016-04-24 12:51         ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 20+ messages in thread
From: Clément Pit--Claudel @ 2016-04-07 17:00 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: Emacs developers


[-- Attachment #1.1.1: Type: text/plain, Size: 314 bytes --]

On 04/07/2016 01:32 PM, Lars Magne Ingebrigtsen wrote:
> Looks good, I think.  One little niggle:
> 
> [...]
> 
>> +                      (format "GNUEmacs/%s" emacs-version)))
> 
> I think "Emacs" is better here.  "GNUEmacs" looks very odd to me.

Thanks! Here is an updated patch.

Cheers,
Clément.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 0001-Take-Emacs-and-package-versions-into-account-in-URL-.patch --]
[-- Type: text/x-diff; name="0001-Take-Emacs-and-package-versions-into-account-in-URL-.patch", Size: 5346 bytes --]

From 38849b1b513a51ffd754c3764b650c0c3428a173 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit--Claudel?= <clement.pitclaudel@live.com>
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))))
 
+(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."
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)
 
-(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 string"))
+(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-level'"
+           :value default))
   :version "25.1"
   :group 'url)
 
-- 
2.8.1


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 14:20           ` Drew Adams
@ 2016-04-07 21:18             ` Richard Stallman
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Stallman @ 2016-04-07 21:18 UTC (permalink / raw)
  To: Drew Adams; +Cc: monnier, emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

The program we are working on is called GNU Emacs.  It is the GNU
implementation of Emacs.  However, we sometimes call it just "Emacs",
for short.

(I don't think "flavor" is correct for distinguishing this programs
from other Emacs implementations -- that word implies something like
an interface theme, except not limited to superficial details.)

-- 
Dr Richard Stallman
President, Free Software Foundation (gnu.org, fsf.org)
Internet Hall-of-Famer (internethalloffame.org)
Skype: No way! See stallman.org/skype.html.




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Help understanding the URL code
  2016-04-07 17:00       ` Clément Pit--Claudel
@ 2016-04-24 12:51         ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 20+ messages in thread
From: Lars Magne Ingebrigtsen @ 2016-04-24 12:51 UTC (permalink / raw)
  To: Clément Pit--Claudel; +Cc: Emacs developers

Clément Pit--Claudel <clement.pit@gmail.com> writes:

> Thanks! Here is an updated patch.

Thanks; applied to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-04-24 12:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-05 15:37 Help understanding the URL code Clément Pit--Claudel
2016-04-05 16:54 ` Andreas Schwab
2016-04-06 11:34 ` Lars Magne Ingebrigtsen
2016-04-07 11:02   ` Clément Pit--Claudel
2016-04-07 12:32     ` Lars Magne Ingebrigtsen
2016-04-07 12:53       ` Andreas Schwab
2016-04-07 13:01         ` Lars Magne Ingebrigtsen
2016-04-07 13:02         ` Yuri Khan
2016-04-07 13:13           ` Andreas Schwab
2016-04-07 13:22             ` Stefan Monnier
2016-04-07 13:32               ` Andreas Schwab
2016-04-07 14:17                 ` Stefan Monnier
2016-04-07 14:28                   ` Andreas Schwab
2016-04-07 15:37                     ` Stefan Monnier
2016-04-07 16:28               ` John Wiegley
2016-04-07 13:07         ` Stefan Monnier
2016-04-07 14:20           ` Drew Adams
2016-04-07 21:18             ` Richard Stallman
2016-04-07 17:00       ` Clément Pit--Claudel
2016-04-24 12:51         ` Lars Magne Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).