Comments (21)
from proxykit.
from proxykit.
Good idea! Wonder if I can leverage something existing to do the work i.e. CacheCow
from proxykit.
from proxykit.
I've done a spike and the caching can be simply implemented using:
var client = ClientExtensions.CreateClient();
app.RunProxy(context =>
{
var forwardContext = context.ForwardTo("upstream-host-url");
return client.SendAsync(forwardContext.UpstreamRequest);
});
Since CacheCow supports using HttpRequestMessage
and HttpResponseMessage
, it integrates nicely with Execute()
.
I would like to live it to you to decide on the best integration design.
from proxykit.
Good start. The small problem with this is that is it not using the HttpClient factory.
from proxykit.
Separate NuGet package maybe?
I think I'll go along with recipe right now as opposed to maintaining integration packages.
from proxykit.
I assume, Damian, that you would like CacheCow to use the HttpClient instance injected into ForwardingContext instead of using own instance?
from proxykit.
I've just noticed that ProxyMiddleware doesn't seem to be using HttpClientFactory provided in the constructor. Is this by design?
from proxykit.
No, that's dead code that I forgot to remove (I'll remove it now). The code of interest is:
from proxykit.
from proxykit.
SharedProxyOptions
has a place to insert a custom HttpMessageHandler that is used when creating the HttpMessageHandler pipeline when creating the HttpClient that is injected into ProxyKitClient
(aka "typed http client"). Am going to see if it's easy to inject CachingHandler
here.
The way HttpClientFactory works is by disposing and re-creating all the handlers on a timed interval. I have a funny feeling that ProxyKit's API as it currently is might not quite be as simple as desired.
from proxykit.
from proxykit.
Can't be static. HttpClientFactory will want to dispose it and recreate it. This can result in ObjectDisposedException
s a couple of minutes into a running system (which doesn't show up in tests). Related #8
from proxykit.
from proxykit.
Yes, singleton CacheStore
from proxykit.
So this appears to work now:
var cacheStore = new InMemoryCacheStore(TimeSpan.FromMinutes(1));
services.AddProxy(options =>
{
options.GetMessageHandler = () => new CachingHandler(cacheStore)
{
InnerHandler = new HttpClientHandler {AllowAutoRedirect = false, UseCookies = false}
};
});
Not quite pit-of-success...
options.GetMessageHandler
is hooked into the HttpClient Factory as the Primary handler. But here CachingHandler is aDelegatingHandler
and I didn't put hook inplace for such. Hence manually setting the InnderHandler...- We're not leveraging the IoC container to activate
InMemoryCacheStore
norCachingHandler
(with ICacheStore being injected into it).
Need to think about this API a bit.
Example CacheCow test code here: https://github.com/damianh/ProxyKit/blob/cachecow/src/ProxyKit.Tests/CacheCowTests.cs#L19
from proxykit.
from proxykit.
You do need to strongly manage the lifecycles of those, yes.
from proxykit.
Thank you very much, Damian!
All working lovely in production :-)
from proxykit.
Production already? Lovely! π
Based on this discussion, I made some improvements to make this easier: #37 . This change was semver breaking so new major version (on nuget.org soon).
Also added recipe for CacheCow and am supporting it via tests
- https://github.com/damianh/ProxyKit/blob/master/src/Recipes/11_CachingWithCacheCow.cs
- https://github.com/damianh/ProxyKit/blob/master/src/ProxyKit.Tests/CacheCowTests.cs
I don't think an integration package is worth it right now but will keep open mind to it if there is more demand and makes things easier.
Thanks for suggestion and the help!
from proxykit.
Related Issues (20)
- 502 Bad Gateway - Azure HOT 8
- Reverse proxy failing for upstream with invalid certificate HOT 1
- 301 response from upstream service causes InvalidOperationException HOT 1
- Is this project dead? HOT 3
- Can I simulate post to log in a website and then reverse it? HOT 1
- Drop TestServer HOT 2
- Run on dedicated endpoint HOT 2
- ProxyKit, YARP and planned obsolescence. HOT 2
- Incorrect forwarding of multiple cookies HOT 4
- Is it possible to route requests to multiple domains? HOT 1
- Is it possible to create end-point along proxying request to upstream services. HOT 1
- Catching WebSocketException HOT 1
- How to set proxy IP with webapi in upstream request? HOT 2
- ForwardTo to a VPN with NetworkCredentials? HOT 1
- How to proxy requests with routing to controllers? HOT 1
- Does that API support to function as a normal http proxy (forward proxy)? HOT 1
- Caching Forwarded Responses HOT 2
- hey! guys, I proxy the web api, how can I delete the response header? HOT 1
- How to log errors? HOT 1
- Migrate to YARP - step by step HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proxykit.