Different pipeline when certain http req header is present

Hi,

Using Phoenix, how do I direct HTTP clients through an alternative pipeline when a certain HTTP request header is present?

I’m guessing a plug could this but pipelines contain plugs so that’s too late in the process. Seems simple enough though, but I can’t find where to start :slight_smile:

tia!

I’m not sure if there’s a way to assign pipelines in a phoenix router other than by path, but you could put your plug into the endpoint.ex and redirect to different routers.

Edit: another option might be a plug, which does only apply another plug supplied in the options on demand.

plug :when_header, plug: MyAppWeb.SomePlug
1 Like

You can put plugs in Controllers too. You can make plugs that run ‘other’ plug lines (it is just simple init/call stuff) depending on various things. Etc… Lot’s of styles, the one I’d pick depends on precisely what is needed to be done.