How to use Emacs url.el lib without asking user about error 401 (unauthorized)?

I want to use url.el (and url-http.el specifically) to make some REST calls programmatically. The user has already specified the credentials using other means (but this is only slightly important - I want to get the same behavior for unauthenticated calls), but for some requests I can get a 401 answer (unauthorized).

I want url.el to just call and return this 401 answer to me without going through all the user's simple request (who will only get annoyed to be asked again).

Note. I created the initial authorization header manually, so I do not use any means from url-auth.el (or that it is being called).


Edit: this works for me (Sacha solution):

(defvar *foobar-within-call* nil
  "Helper variable to indicate if we are withing a foobar call and thus won't want the authentication mechanisms to kick in")

(defadvice url-http-handle-authentication (around foobar-fix)
  (unless *foobar-within-call*
      ad-do-it))
(ad-activate 'url-http-handle-authentication)
+3
source share
1 answer

I suppose you could add some tips around url-http-handle authentication ...

+3
source

Source: https://habr.com/ru/post/1718703/


All Articles