-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
No way to provide my own HttpClient or HttpMessageHandler #801
Comments
I'm working on a PR to fix this. Hopefully ready weekly next week. I'm adding a method to |
This is not a bug, the change was intentional. You have a couple possible work-arounds:
I'll try and explain my reasons for the change. In 3.x and earlier, if you wanted to configure something that lives on HttpClientHandler, such as a certificate or proxy (very common scenarios), the answer was to create and register a custom factory. Now the way to do it is with a fluent one-liner via I always had it in the back of my mind that I'd be taking away the ability to provide an entirely new inner handler (except via option 2 above), and I wondered if and when someone would have a legitimate use case to do that in Flurl. You could say that day arrived sooner than I expected. :) I'm willing to look at your PR and give it some thought, but I do still think the use cases are quite rare and I have the concern that making it "too easy" could steer some people in the wrong direction, if that makes sense. |
Could you clarify how to use a custom I can't derive from the migration guide how to replicate that behavior. Edit: Having looked a bit more, it seems that the primary thing we used the Factory was to define a BaseAddress for all tests. I.e. we did (simplified) I would have assumed that I simply need to configure the base address:
and could then use clientless operations:
However that fails, because the base address is not prefixed. |
@lennartb- I would expect what you did with |
Thanks, I'll try to repro it tomorrow in an isolated project and report back |
@lennartb- I just confirmed that you uncovered a bug. I'll get it logged and fixed. Thank you. |
@lennartb- Fixed & released: #803 |
Thank you, now the base address gets prefixed as expected. However we still can't seem to configure the default clients correctly, the base address doesnt seem to be enough. If we use the clientless pattern, all calls fail with e.g.
But, If I use a
Now, this would be an okay workaround for us, but we'd still have to update our tests to use an explicit client instead of the (very comfortable) clientless extension methods. I've compared both objects (client from the clientless builder and our manual client) and can't find any obvious differences., all properties seem to be equivalent. Maybe it's related to the
|
Managed to get it to work, it feels a bit hacky but is not too bad:
where
Disposing and replacing the |
@lennartb- Excellent, I'm glad to hear that worked! It probably would have taken me a bit of time to arrive at that as well, what exactly WebApplicationFactory does under the hood was still a bit of a mystery to me so I learned something here too. If you want to get more visibility of this technique, you might consider posting it here. (My answer there still holds but yours could start with "If you want to use the clientless pattern..." or something.) I do have a longer-term goal of releasing a Flurl companion library for ASP.NET Core. It would likely include extensions for integration testing, MS's DI container, and Polly. Should make things like this easier. I wasn't planning on covering clientless in testing...but maybe. |
I tried @lennartb- solution, if I call more than one request I get I ended up using |
as in I am also getting this message when calling multiple requests |
Yes
Later
|
I hope it's me being stupid, but I can't work out how to provide my own
HttpMessageHandler
. My use-case is I have created an implementation ofHttpMessageHandler
that sends and receives over Azure Relay - it's not doing conventional socket-based stuff directly. I can also see how I might want to use e.g. MockHttp which also replaces the stock HttpMessageHandler in the HttpClient.I can see the
IFlurlClientFactory
appears to be what I want to implement, but the public API doesn't let me set theIFlurlClientFactory
_factory
member variable insideFlurlClientBuilder
. In fact it's either aDefaultFlurlClientFactory
or it's aSocketsHandlerFlurlClientFactory
, and neither of them will work for me. Short of lots of nasty reflection, I think 4.0 has lost the ability that 3.x had to customise the creation of theHttpMessageHandler
and that's a show-stopper for me.The text was updated successfully, but these errors were encountered: