Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply routing constraint to […] bind? #1636

Open
richard-giraud opened this issue Feb 12, 2024 · 3 comments
Open

Apply routing constraint to […] bind? #1636

richard-giraud opened this issue Feb 12, 2024 · 3 comments

Comments

@richard-giraud
Copy link

Hello,

Is it possible to apply a constraint to the binding? I’m trying to use the :cowboy_static handler while keeping certain files from being served (e.g., *.php). I can apply a constraint to any of the regular binds and not that one; it doesn’t seem to come up in the list of binds.

If it’s not available, a syntax like [:foo…] may be a good approach. If that is of interest, I can try to implement it.

Thank you in advane.

@essen
Copy link
Member

essen commented Feb 12, 2024

You can't because constraints are applied to bindings and '_' doesn't bind anything.

The best approach for your case is probably to write a middleware that you put between cowboy_router and cowboy_handler that would check if it's a PHP file and change the handler and handler_opts value based on that, or simply stop the request there and return a 4xx error.

@richard-giraud
Copy link
Author

@essen Thank you for response I appreciate you clarifying what is possible at this time and I will investigate the approach you recommended.

Is the omission of this feature a design choice? Or is it desirable and simply not implemented yet?

If this is a feature that is not wanted, I think there is value in updating the documentation to explicitly mention that using constraints with […] is not possible. It may save the next person some of the hours that I spent trying to figure it out.

I’m happy to help with this as best as I can. Please let me know if either of the above appeals to you and I will do my best to craft a suitable PR.

Thanks again

@essen
Copy link
Member

essen commented Feb 12, 2024

Documentation updates are always welcome, regardless of why things are as they are.

In this case, the code is a few years old so I'm not sure why it's only applying to explicitly bound values. I likely have not thought about using them with '_' or '...' yet. Experimenting with this would be welcome but note that I don't know what it should look like at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants