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

Make .forHostname() hostname parameter a RegExp #82

Open
OnkelTem opened this issue May 12, 2022 · 2 comments
Open

Make .forHostname() hostname parameter a RegExp #82

OnkelTem opened this issue May 12, 2022 · 2 comments

Comments

@OnkelTem
Copy link

OnkelTem commented May 12, 2022

I'd propose to make hostname a RegExp.
First, to match things like: .forHostname(/^.+?\.domain.com/)
Second, to keep up with the URL matchers (.forGet(), .forPost() etc) which can take RegExp.

I.e.

forHostname(hostname: string): this;

gets:

forHostname(hostname: string | RegExp): this;
@pimterry
Copy link
Member

👍 Sounds good to me, PRs welcome. The one tricky bit is serialization for remote clients, since JSON can't represent regexes natively.

You can see how RegexPathMatcher handles it here - it stores the regex as a string, which only gets converted into a regex inside matches(req).

I think I'd suggest creating this as a new matcher like RegexHostnameMatcher, with the forHostname method choosing between the two implementations. That's the same way that path matching works to do strings + regexes, and that way you don't have to differentiate between the raw-string and regex-serialized--as-string data when deserializing rules from remote clients.

@OnkelTem
Copy link
Author

Got you!

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