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

Configurable target URI rewrites #58

Merged
merged 1 commit into from
May 17, 2024

Conversation

tgeoghegan
Copy link
Contributor

Add a TARGET_REWRITES environment variable that allows rewriting the URI in an encapsulated request. See changes to README.md for discussion of motivation and utilization.

Closes #56

@tgeoghegan
Copy link
Contributor Author

If the maintainers agree with this approach, then I'd be happy to add some tests to exercise it.

Then the encapsulated HTTP requests

```http
POST /some-cool-api HTTP/1.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this happening in the code change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will add a test that exercises the target rewrite feature before merging this.

@bwesterb bwesterb self-requested a review May 7, 2024 11:52
@cjpatton
Copy link

cjpatton commented May 7, 2024

The documentation should clarify whether the set up described is suitable for production OHTTP deployment.

If the maintainers agree with this approach, then I'd be happy to add some tests to exercise it.

The approach seems reasonable, go ahead and work on tests. Are unit tests feasible?

@tgeoghegan
Copy link
Contributor Author

The documentation should clarify whether the set up described is suitable for production OHTTP deployment.

As I explained in #56, I do want this for production setups, assuming the maintainers agree this isn't dangerous in some way I haven't seen.

If the maintainers agree with this approach, then I'd be happy to add some tests to exercise it.

The approach seems reasonable, go ahead and work on tests. Are unit tests feasible?

Yeah, I can copy some setup from the existing tests to exercise this.

@@ -5,11 +5,13 @@ package main

Copy link
Contributor Author

@tgeoghegan tgeoghegan May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to refactor these tests a little because the mock gateway created in createMockEchoGatewayServer never actually used FilteredHttpRequestHandler, which is where both forbidden/allowed origins and target rewrites are implemented. Now, instead of using ForbiddenCheckHttpRequestHandler which would just fire metrics and send a canned response, we wire MockHttpRequestHandler into ProtoHTTPAppHandler or BinaryHTTPAppHandler. FilteredHttpRequestHandler takes an implementation of interface HttpRequestHandler so that we can swap out MockHttpRequestHandler instead of a real http.Client.

@bwesterb, @cjpatton: PTAL

@tgeoghegan tgeoghegan requested a review from bwesterb May 9, 2024 21:22
handler.go Show resolved Hide resolved
@bwesterb
Copy link
Member

Looks good to me. Just need approval from a second owner.

@cjpatton
Copy link

Looks good to me. Just need approval from a second owner.

in my queue.

Copy link

@cjpatton cjpatton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks pretty good, just one question.

Plus: unfortunately we have a mix of "Http" and "HTTP" in this codebase. For new variables I'd like to lean towards "HTTP" as it matches Go convention.

gateway_test.go Outdated Show resolved Hide resolved
gateway_test.go Outdated Show resolved Hide resolved
gateway_test.go Outdated Show resolved Hide resolved
handler.go Outdated Show resolved Hide resolved
handler.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
handler.go Outdated Show resolved Hide resolved
@cjpatton
Copy link

LGTM, @tgeoghegan. Please squash and I'll merge.

Add a `TARGET_REWRITES` environment variable that allows rewriting the
URI in an encapsulated request. See changes to `README.md` for
discussion of motivation and utilization.
@cjpatton cjpatton merged commit 1d8081f into cloudflare:main May 17, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

Redirecting to a target on loopback
3 participants