pedestal

ccann 2019-05-30T20:39:34.001200Z

could anyone recommend a way to have the allowed-origins interceptor skip a particular route?

2019-05-30T20:45:35.004800Z

@ccann, you have full control over what interceptors are added. Leveraging Pedestal’s default-interceptors impl should be considered a convenience and may not be suitable for some use cases. By setting the :io.pedestal.http/interceptors key on the service map you take full control over what interceptors are added when. If you do this, though, you’ll need to add the router interceptor yourself.

ccann 2019-05-30T20:46:15.005900Z

okay yeah, thanks

2019-05-30T20:46:54.006700Z

Or you can just add the allowed-origins interceptor yourself in your routes and skip specifying the allowed-origins in your service map

2019-05-30T20:47:08.006900Z

the later is probably more confusing

ccann 2019-05-30T20:51:25.007800Z

the problem I’m having that led me to ask the question is that for my health check route (a GET request) I’m getting a NPE from my allowed-origins function

ccann 2019-05-30T20:51:33.008100Z

which is because there is no Origin header (i’m parsing the header with a regexp)

ccann 2019-05-30T20:51:47.008500Z

because the health check is coming from an AWS server not a browser

ccann 2019-05-30T20:52:31.009400Z

and apparently the pedestal cors interceptor calls the allowed-origins function before determining if the request type is :options https://github.com/pedestal/pedestal/blob/09dd88c4ce7f89c7fbb7a398077eb970b3785d2d/service/src/io/pedestal/http/cors.clj#L82

2019-05-30T20:55:03.010400Z

Yep, the allow-origin interceptor is added prior to the router and it is within the router where method-based matching is done

ccann 2019-05-30T20:58:59.011900Z

so I guess the “correct” behavior then for a missing Origin header is for the allowed-origins function to return truthy

ccann 2019-05-30T21:00:34.013800Z

because a browser is going to send Origin, and that’s what CORS is concerned with. If a server or curl doesn’t specify an origin that’s outside the concern of CORS

ccann 2019-05-30T21:00:51.014200Z

thinking out-loud here 🙂

2019-05-30T21:05:12.014500Z

sounds reasonable

❤️ 1