tags:

views:

228

answers:

1

I want to use url.el (and url-http.el specifically) to make some REST calls programmatically. The user has already specified the credentials via other means (but this is only mildly relevant -- I want to get the same behaviour for un-authenticated calls as well) but on certain queries I can still get a 401 (Unauthorized) response.

I want url.el to just let it be and return me that 401 response without going through all the rigmarole of asking the user (who will only get annoyed to be asked again).

Note: I created the initial authorization header manually, so I am not using any facilities from the url-auth.el (or whatever it is called).


Edit: This seems to work for me (solution provided by Sacha):

(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  A: 

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

Sacha Chua
That worked indeed. I had forgotten about defadvice and tried flet binding a new definition temporarily which somehow didn't work.My current solution now is something along these lines: (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)
HD