all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mark Schreiber <mark7@alumni.cmu.edu>
To: 24365@debbugs.gnu.org
Subject: bug#24365: 24.4; [PATCH] url-http-options fails when connection refused
Date: Sun, 04 Sep 2016 01:15:24 -0700	[thread overview]
Message-ID: <87inucqdwj.fsf@war.peplook.com> (raw)

url-http-options fails when a web server refuses its connection.

Evaluating (url-http-options "http://127.0.0.1:33333/") results in the
following error:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  url-http-options("http://127.0.0.1:33333/")
  eval((url-http-options "http://127.0.0.1:33333/") nil)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

In my case, this caused the third-party package org-caldav to fail with
this error when M-x org-caldav-sync was invoked and given an incorrect
org-caldav-url.

I believe that the correct behavior would be to have url-http-options
return nil, which is the behavior of that function when it receives an
HTTP error response.

The issue is still present in master.  The following patch against
master causes url-http-options to return nil in the above case.
---
url-http-options would fail internally when passed an URL to a
web server refusing the connection.  Change its behavior to return nil,
as would occur if an HTTP error code were received.

* lisp/url/url-http.el (url-http-options)

Copyright-paperwork-exempt: yes
---
 lisp/url/url-http.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 927d0bb..e55b645 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -1512,10 +1512,11 @@ url-http-options
   (let* ((url-request-method "OPTIONS")
 	 (url-request-data nil)
 	 (buffer (url-retrieve-synchronously url))
+         (response-status (when buffer (url-http-symbol-value-in-buffer
+                                        'url-http-response-status buffer 0)))
 	 (header nil)
 	 (options nil))
-    (when (and buffer (= 2 (/ (url-http-symbol-value-in-buffer
-			       'url-http-response-status buffer 0) 100)))
+    (when (and response-status (= 2 (/ response-status 100)))
       ;; Only parse the options if we got a 2xx response code!
       (with-current-buffer buffer
 	(save-restriction
-- 
2.1.4






             reply	other threads:[~2016-09-04  8:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-04  8:15 Mark Schreiber [this message]
2017-12-06 10:47 ` bug#24365: 24.4; [PATCH] url-http-options fails when connection refused Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87inucqdwj.fsf@war.peplook.com \
    --to=mark7@alumni.cmu.edu \
    --cc=24365@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.