Subject: bug#8931: 24.0.50; url-http.el terminating HTTP packets with extra carriage return and newline

From: Nicolas Avrutin <[email-masked]>
Date: Fri, 24 Jun 2011 15:45:36 -0400

`browse-url-emacs' and `url-retrieve-synchronously' (and probably other
functions) appear to be generating malformed HTTP packets by appending an
extra \r\n to the packet, resulting in them being terminated with "\r\n\r\n"
instead of "\r\n". Some pages (such as http://www.google.com) to still
return properly and just send back a packet saying that the sent packet was
malformed. Other pages, in my case last.fm's client API (access via
emms-lastfm-client) return 400 Bad Request. In addition, this causes
Wireshark to report the packet as "HEAD / HTTP/1.1 Continuation or non-HTTP
traffic".

Removing the "\r\n" on line 341 of url-http.el (see attached patch) removes
the duplicate "'\r\n" and appears to fix the issue. Calls to last.fm's
client API return 200 OK as expected and Wireshark properly reports the
packet as "HEAD / HTTP/1.1". Google, however, still reports a malformed
packet.

This bug is preset in Emacs 23.1, but is not in 23.2. My patch restores the
line to what it was in 23.2, but I do not know if it was changed for a
reason or in error.

--
Nicolas Avrutin
*** url-http.el	2011-06-24 15:11:53.186238893 -0400
--- url-http.el.patched	2011-06-24 15:11:00.232907619 -0400
***************
*** 338,344 ****
               ;; End request
               "\r\n"
               ;; Any data
!              url-http-data "\r\n"))
             ""))
      (url-http-debug "Request is: \n%s" request)
      request))
--- 338,344 ----
               ;; End request
               "\r\n"
               ;; Any data
!              url-http-data))
             ""))
      (url-http-debug "Request is: \n%s" request)
      request))