If your service map already includes the key
:io.pedestal.http/interceptors when you call one of the
functions, then Pedestal won’t add the default interceptors. So what
should you do if you want to use the default interceptors, but want to
add your own interceptors to the default stack?
The solution is to call
yourself, before calling
default-interceptors can build the default stack, then your
application code has an opportunity to modify it. By the time you call
:io.pedestal.http/interceptors key will have your modified version
of the default interceptors.
Here is an example of adding interceptors to perform authentication
and authorization on every request. (Assuming we have a namespace
auth with functions to construct these interceptors given a
[service-map authn-config authz-config]
(update ::http/interceptors conj (auth/authentication-interceptor authn-config)) (2)
(update ::http/interceptors conj (auth/authorization-interceptor authz-config)) (3)
||Attach the default interceptors to our service map
||Modify the defaults to add authentication.
||Further modify the defaults to add authorization.
||Create the server as usual. This would normally attach the defaults, but will skip that because we’ve set them up ourselves.