tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

Fix errors with using curl for file: URLs #127

Closed Miciah closed 5 years ago

Miciah commented 5 years ago

Do not try to parse headers if the backend is curl and the URL does not have the "http" or "https" scheme, and tolerate a nil value for the response status code. Curl does not print headers for "file:" or other non-HTTP URLs.


This change improves one common case but has one shortcoming. If no scheme is specified, curl tries to guess the scheme, defaulting to HTTP, and curl's heuristic for guessing the scheme is not detailed in the manpage, so trying to replicate the heuristic would produce fragile logic. Instead, I change request--curl-callback to assume that curl will default to HTTP. This change should thus improve the common case of using a URL with an explicit, non-HTTP scheme, without breaking the cases of using a URL with an explicit HTTP scheme or using a URL without an explicit scheme where curl guesses HTTP; however, it does not address the case of using a URL without an explicit scheme where curl guesses a non-HTTP scheme (request--curl-callback will erroneously continue to try to parse headers in this case).

dickmao commented 5 years ago

I would rather disallow URLs that are not of type http or https, then permit an arbitrary type and have to add tests for them.

tkf very clearly intended this library to be used for HTTP requests only.

dickmao commented 5 years ago

I've added a test for file:///foo/bar and subsumed your PR into #129 . Thank you.