servicestack: adding www-authenticate header to an error response -


when throwing 401 error because of missing authorization, want include www-authenticate header.

but how do that?

i tried response filter, didn't seem work.

edit

my response filter ain't called when httperror thrown:

apphost.responsefilters.add((req, res, obj) => res.addheader(httpheaders.wwwauthenticate, "basic realm=...")); 

exception handlers called added header not part of response (according both chrome dev tools , postman)

apphost.exceptionhandler += (req, res, name, exception) => res.addheader(httpheaders.wwwauthenticate, "basic realm=..."); 

i can't find hooks can add response headers:

  • responsefilters ain't called after exception thrown.
  • serviceexceptionhandler doesn't provide response object.
  • exceptionhandler called after response sent, it's late.

since check credentials in request filter, have access response object there. ended custom exception logonexception can trap , add header:

apphost.requestfilters.add(     (req, res, obj) =>      {         var creds = request.getbasicauthuserandpassword();          try         {             myservice.logon(creds);         }         catch(logonexception)         {             res.addheader(httpheaders.wwwauthenticate, "basic realm=...");             trow;         }     }); 

Comments