core icon indicating copy to clipboard operation
core copied to clipboard

HttpClient support for specifying local end point

Open kdotdk opened this issue 2 years ago • 2 comments

Background

WebRequest class has been deprecated. Deprecation recommendation is to use .Net HttpClient and third party FTP client instead.

Problem

WebRequest supports setting local end point with ServicePoint.BindIPEndPointDelegate. The suggest third party FTP client support setting local IP end point but .Net HttpClient can not replace HttpWebRequest because it does not support setting local IP end point.

Solution

Add support for setting local IP end point for HttpClient or add a list of third party HTTP clients support setting local IP end point to the deprecation recommendation.

kdotdk avatar Mar 27 '23 10:03 kdotdk

cc @MihaZupan any ideas here?

layomia avatar Mar 27 '23 21:03 layomia

An Idea (If HttpClient internally uses TCPClient): Expose the used TCPClient as a property or allow passing a TCPClient to the construction of a HttpClient. This way you can create a custom socket bound to a local end point by passing your own TCPClient or assign your own socket to the HttpClient.TCPClient.Client property Pseudo Code:

var localEndPoint = new IPEndPoint(...);
var socket = new Socket(...);
socket.Bind(localEndPoint);
var httpClient = new HttpClient();
httpClient.TCPClient.Client = socket;
httpClient.Send(...)

kdotdk avatar Mar 29 '23 07:03 kdotdk