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

Integrate ITransformProvider with ITransformBuilder.Create Method #2626

Open
PascalSenn opened this issue Oct 9, 2024 · 1 comment
Open

Comments

@PascalSenn
Copy link

PascalSenn commented Oct 9, 2024

Hi there,

I'm currently using YARP to forward requests directly with MapForwarder, as well as through Duende BFF, which uses YARP internally.

I'm implementing a token exchange mechanism and need to intercept the request headers. I believe using the ITransformProvider would be suitable for this task, as it allows appending RequestTransform to the route.

However, I've encountered a problem: both MapForwarder and Duende BFF call the Create method, which does not execute any of the transform providers, as seen in the following code snippet:
TransformBuilder.cs - Lines 139-179.

Currently, it appears that there's no way to apply a generic configuration across all YARP use cases. Overriding ITransformBuilder seems the only way, but the default implementation is internal which doesnt make this easier.

I think adding the ITransformProvider capabilities to the Create method would pretty much solve all of these issues.

What are your thoughts on this approach? Is there anything I might have overlooked?

Thank you!

@PascalSenn PascalSenn changed the title Integrate ITransformFactory with ITransformBuilder.Create Method Integrate ITransformProvider with ITransformBuilder.Create Method Oct 9, 2024
@MihaZupan
Copy link
Member

MihaZupan commented Oct 29, 2024

Essentially the difference is that ITransformProvider and ITransformBuilder.Build expect there to be a route definition, whereas Create does not.
The expectation was that the former would be used when you're using the routes/clusters configuration model and may need to adjust functionality depending on each route, and Create would be used when using direct forwarding to let you reuse transform logic (e.g. your class derived from RequestTransform) between the two, where it's unlikely that you'll have any transform providers registered.

As far as I can tell, BFF has an IHttpTransformerFactory interface where you could inject your transform, though that might mean duplicating any default logic they have there.

MapForwarder are very simple convenience APIs when you don't need a lot of customization, and there's an overload that lets you modify the TransformBuilderContext. Getting the desired behavior there might mean just adding the transform there.

-.AddTransforms<MyTransformProvider>();
-app.MapForwarder("/foo", "bar");
+app.MapForwarder("/foo", "bar", ctx => ctx.RequestTransforms.Add(new MyTransform()));

As mentioned above, I don't think we expected Create to be used together with ITransformProvider, but I think it'd be fine if we changed the behavior here and called into providers (after creating a fake RouteConfig).

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