async Task AdAsync(MHttpStream localStream) { try { var response = MHttpResponse.Create(200); response.SetContent(m_info.ADVideoBytes); await response.SendAsync(localStream).ConfigureAwait(false); } finally { localStream?.Close(); } }
static void ReadConnectRequest(Socket socket, Func <string, TunnelPackAction> func) { Task.Run(async() => { Stream stream = new NetworkStream(socket, true); MHttpStream httpStream = new MHttpStream(socket, stream, 1024); MHttpRequest request = await MHttpRequest.ReadAsync(httpStream, 1024 * 1024).ConfigureAwait(false); MHttpResponse response = MHttpResponse.Create(200); await response.SendAsync(httpStream).ConfigureAwait(false); Uri uri = new Uri($"http://{request.Path}/"); func(uri.Host)(uri, new TunnelPack(socket, stream)); }); }