Salvaging .Net’s HttpClient

See the original posting on DZone Python

If you read my previous article, it’s easy to become frustrated. HttpClient is at the core of everything we as software developers normally do when we integrate our stuff with other people’s stuff. Somebody sounding the alarm, telling you that it’s fundamentally broken, might result in everything ranging from a general concern about ones own code, to flat out panic attacks. Hence, I figured I’d be an asshole unless I also showed you an alternative.

Paradoxically, fixing HttpClient is very easy, it’s just to cut away everything in it that’s dangerous, and encapsulate everything that’s beautiful about it into a much safer API, making it impossible for developers to retrieve the instance to the HttpClient you’re using internally. Basically, treat most of HttpClient’s API as if it was cancer, and salvage the rest. Here’s a much safer version in case you care. For the record, to understand this class, you have to read my previous article here at DZone.