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

v2: new directives for fast substring URI manipulation #2906

Closed
whitestrake opened this issue Nov 29, 2019 · 9 comments
Closed

v2: new directives for fast substring URI manipulation #2906

whitestrake opened this issue Nov 29, 2019 · 9 comments

Comments

@whitestrake
Copy link
Collaborator

@whitestrake whitestrake commented Nov 29, 2019

1. What would you like to have changed?

Addition of multiple new v2 Caddyfile directives, which will leverage the rewrite handler to make common fast URI manipulations possible without having to use complicated regex matching and placeholders.

strip_prefix [<matcher>] prefix

  • prefix is the string to be removed from the start of the request path.

strip_suffix [<matcher>] suffix

  • suffix is the string to be removed from the end of the request path.

uri_replace [<matcher>] string replacement [max_replacements]

  • string is the string to be replaced.
  • replacement is the string to put in the original string's place.
  • max_replacements is the maximum number of instances of string to replace. Set to 0 for infinite replacements. Default 0.

2. Why is this feature a useful, necessary, and/or important addition to this project?

There are several use cases that benefit from being able to easily perform these common manipulations. Notably, the without subdirective of the v1 Caddyfile's proxy directive is strictly not achievable right now.

3. What alternatives are there, or what are you doing in the meantime to work around the lack of this feature?

For the without use case, a similar result is possible by rewriting using a complex regex matcher and placeholders, but I believe at the moment the reverse proxy must be scoped to the resulting rewritten URI rather than the original URI - which results in a strictly different behaviour than proxy without.

4. Please link to any relevant issues, pull requests, or other discussions.

A recent discussion around the without use case in v2:
https://caddy.community/t/v2-rewrite-proxy/6555?u=whitestrake

@mholt mholt added the v2 label Nov 29, 2019
@mholt mholt added this to the 2.0 milestone Nov 29, 2019
@mholt

This comment has been minimized.

Copy link
Member

@mholt mholt commented Nov 29, 2019

Technically, these directives will accept (optional) matcher tokens as their first arguments as well.

@whitestrake

This comment has been minimized.

Copy link
Collaborator Author

@whitestrake whitestrake commented Nov 29, 2019

Good point, just threw in [<matcher>] optional first tokens in an edit.

@mholt

This comment has been minimized.

Copy link
Member

@mholt mholt commented Nov 29, 2019

I might also clarify that strip_prefix and strip_suffix are for URI path only, not entire URI (query string, etc). However, uri_replace will operate on the whole URI... right?

@whitestrake

This comment has been minimized.

Copy link
Collaborator Author

@whitestrake whitestrake commented Nov 29, 2019

Yes, that makes sense. And uri_replace is arbitrary, and could be useful for queries, so there's no reason to limit it to the path only.

Do you think it's worth renaming them to strip_path_prefix and strip_path_suffix?

@mholt

This comment has been minimized.

Copy link
Member

@mholt mholt commented Nov 29, 2019

Good question, I'm not sure. I like the brevity of strip_prefix and strip_suffix and I feel like it's mostly obvious because query strings aren't ordered, hence they have no prefix/suffix... maybe just need to clarify in the docs?

@whitestrake

This comment has been minimized.

Copy link
Collaborator Author

@whitestrake whitestrake commented Nov 29, 2019

Edited to clarify above, specifically, s/of the URI/of the request path/.

@mholt mholt modified the milestones: 2.0, v2.0.0-beta11 Nov 29, 2019
@sarge

This comment has been minimized.

Copy link

@sarge sarge commented Dec 11, 2019

@whitestrake How would these new directives work with the reverse proxy?
To simulate the without you want them to work after the reverse proxy is chosen. But in other cases you might want them to occur before the reverse proxy to create an alias?
I thought I read that directives were not intended to be nested, is this a case where we might make an exception?

Perhaps covered elsewhere, why was without omitted from v2? Too specific?

@sarge

This comment has been minimized.

Copy link

@sarge sarge commented Dec 12, 2019

@whitestrake I understand now how these new directives along with the route directive will provide the composition of behaviours that without achieved.

mholt added a commit that referenced this issue Dec 12, 2019
@mholt

This comment has been minimized.

Copy link
Member

@mholt mholt commented Dec 12, 2019

Implemented in b1a456c!

@mholt mholt closed this Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.