private async Task <CustomHttpsClient> GetClient(string host, int port) { const string version = "HTTP/1.1"; var proxyUrl = Environment.GetEnvironmentVariable("http_proxy"); return(proxyUrl == null ? await CustomHttpsClient.CreateWithoutProxy(host, port, version) : await CustomHttpsClient.CreateWithProxy(host, port, version, proxyUrl)); }
static async Task <CustomHttpsClient> GetClient(string host, int port, string version) { //var proxyUrl = Environment.GetEnvironmentVariable("http_proxy"); var proxyUrl = "http://localhost:8888"; return(proxyUrl == null ? await CustomHttpsClient.CreateWithoutProxy(host, port, version) : await CustomHttpsClient.CreateWithProxy(host, port, version, proxyUrl)); }
public async Task ConnectTest() { const string host = "raw.githubusercontent.com"; const int port = 443; const string version = "HTTP/1.1"; // const string requestText = "CONNECT raw.githubusercontent.com:443 HTTP/1.1\r\nHost: raw.githubusercontent.com:443\r\n\r\n"; // var parsedRequest = Request.Parse(requestText); var proxyUrl = Environment.GetEnvironmentVariable("http_proxy"); // var customHttpsClient = await CustomHttpsClient.CreateWithProxy(host, port, proxyUrl); var customHttpsClient = new CustomHttpsClient(host, port, version, proxyUrl); await customHttpsClient.HandleConnect(); }
static async Task HandleHttpsRequests(ClientInfo clientInfo, int receiveBufferSize, CustomHttpsClient httpsClient) { while (true) { var cts = new CancellationTokenSource(105 * 1000); // receive http request from client var requestBytes = await ReceiveHttpRequestBytes(clientInfo.Stream, receiveBufferSize, cts.Token); var requestText = Encoding.UTF8.GetString(requestBytes); var line = new string(requestText.Replace("\r\n\r\n", "").Replace("\r\n", " ").Take(95).ToArray()); //var line = requestText.Replace("\r\n\r\n", "").Replace("\r\n", " "); WriteLine($"client '{clientInfo.Id}' req: '{line}'"); // send request to remote var rawResponse = await httpsClient.HandleSend(requestText); var responseText = Encoding.UTF8.GetString(rawResponse); // forward response to client await clientInfo.Stream.WriteAsync(rawResponse, cts.Token); if (responseText.Contains("Connection: close")) { throw new IOException("closing connection"); } } }