Closed Miciah closed 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.
I've added a test for file:///foo/bar
and subsumed your PR into #129 . Thank you.
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.
request.el
(request--parse-data
): Useequal
, which tolerates nil, to compare the response status code. (request--callback
): Do not try to parse headers if using curl and not using "http:" or "https:". (request--curl-callback
): Check whether the response status code is nil.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).