Is there a way to modify the cookies before it gets proxied? #2140
-
Hi there, first, thanks for YARP, this is such an awesome project! I`m quite new to working with reverse proxies so please forgive my mistakes describing my "issue". I have a working implementation of my usecase using YARP. The destination has problems with cookies, so I used the "RequestHeaderRemove" to remove the cookie header. This works. Finally my question: instead of removing the Cookie Header all together, I would love to inspect the cookies and remove only certain cookies (in the concrete case I want to remove only ASP.NET Auth cookies). Is there a way to do that? I looked at a CustomTransformer from the direct forwarding example and inspected the HttpRequestMessage proxyRequest, but there is no way to set or modify cookies. Any hint that points me in a direction to check on my own would be great. Thank you very much and have a great day. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You're on the right track with the CustomTransformer. A similar sample is here: reverse-proxy/samples/ReverseProxy.Transforms.Sample/Startup.cs Lines 48 to 55 in ad6ee6a
The cookies are just a non-special header in the request headers collection, you can call TryGetValues to get the current cookies, Remove("Cookies") to drop everything, and Add or TryAddWithoutValidation to re-set the header with your modified cookies. |
Beta Was this translation helpful? Give feedback.
You're on the right track with the CustomTransformer. A similar sample is here:
reverse-proxy/samples/ReverseProxy.Transforms.Sample/Startup.cs
Lines 48 to 55 in ad6ee6a