private async void Process() { try { await InitializeStream(); while (_client.Connected) { // TODO : Configuration. var limitedStream = new NotFlushingStream(new LimitedStream(_stream)); var request = await _requestProvider.Provide(new MyStreamReader(limitedStream)).ConfigureAwait(false); if (request != null) { UpdateLastOperationTime(); var context = new HttpContext(request, _client.RemoteEndPoint); Logger.InfoFormat("{1} : Got request {0}", request.Uri, _client.RemoteEndPoint); await _requestHandler(context).ConfigureAwait(false); if (context.Response != null) { var streamWriter = new StreamWriter(limitedStream) { AutoFlush = false }; streamWriter.NewLine = "\r\n"; await WriteResponse(context, streamWriter).ConfigureAwait(false); await limitedStream.ExplicitFlushAsync().ConfigureAwait(false); if (!request.Headers.KeepAliveConnection() || context.Response.CloseConnection) { _client.Close(); } } UpdateLastOperationTime(); } else { _client.Close(); } } } catch (Exception e) { // Hate people who make bad calls. Logger.WarnException(string.Format("Error while serving : {0}", _remoteEndPoint), e); _client.Close(); } Logger.InfoFormat("Lost Client {0}", _remoteEndPoint); }
private async void Process() { try { while (_client.Connected) { // TODO : Configuration. var limitedStream = new NotFlushingStream(new LimitedStream(_stream, readLimit: 1024 * 1024, writeLimit: 1024 * 1024)); var streamReader = new StreamReader(limitedStream); var request = await _requestProvider.Provide(streamReader).ConfigureAwait(false); if (request != null) { UpdateLastOperationTime(); var context = new HttpContext(request, _client.RemoteEndPoint); Log.Information("{endpoint} : Got request {uri}", _client.RemoteEndPoint, request.Uri); await _requestHandler(context).ConfigureAwait(false); if (context.Response != null) { var streamWriter = new StreamWriter(limitedStream) { AutoFlush = false }; await WriteResponse(context, streamWriter).ConfigureAwait(false); await limitedStream.ExplicitFlushAsync().ConfigureAwait(false); if (!request.Headers.KeepAliveConnection() || context.Response.CloseConnection) { _client.Close(); } } UpdateLastOperationTime(); } else { _client.Close(); } } } catch (Exception e) { // Hate people who make bad calls. Log.Warning(e, "Error while serving : {endpoint}", _remoteEndPoint); _client.Close(); } Log.Information("Lost Client {endpoint}", _remoteEndPoint); }
private async void Process() { try { while (_client.Connected) { // TODO : Configuration. var limitedStream = new NotFlushingStream(new LimitedStream(_stream)); var request = await _requestProvider.Provide(new MyStreamReader(limitedStream)).ConfigureAwait(false); if (request != null) { UpdateLastOperationTime(); var context = new HttpContext(request, _client.RemoteEndPoint); Logger.InfoFormat("{1} : Got request {0}", request.Uri, _client.RemoteEndPoint); await _requestHandler(context).ConfigureAwait(false); if (context.Response != null) { var streamWriter = new StreamWriter(limitedStream) { AutoFlush = false }; await WriteResponse(context, streamWriter).ConfigureAwait(false); await limitedStream.ExplicitFlushAsync().ConfigureAwait(false); if (!request.Headers.KeepAliveConnection() || context.Response.CloseConnection) { _client.Close(); } } UpdateLastOperationTime(); } else { _client.Close(); } } } catch (Exception e) { // Hate people who make bad calls. Logger.WarnException(string.Format("Error while serving : {0}", _remoteEndPoint), e); _client.Close(); } Logger.InfoFormat("Lost Client {0}", _remoteEndPoint); }
private async void Process() { try { while (Client.Connected) { // TODO : Configuration. var limitedStream = new NotFlushingStream(new LimitedStream(_stream, 1024 * 1024, 1024 * 1024)); var streamReader = new StreamReader(limitedStream); var request = await _requestProvider.Provide(streamReader).ConfigureAwait(false); if (request != null) { UpdateLastOperationTime(); var context = new HttpContext(request, Client.RemoteEndPoint); _logger?.Debug($"{Client.RemoteEndPoint} : Got request {request.Uri}"); await _requestHandler(context).ConfigureAwait(false); if (context.Response != null) { var streamWriter = new StreamWriter(limitedStream) { AutoFlush = false }; await WriteResponse(context, streamWriter).ConfigureAwait(false); await limitedStream.ExplicitFlushAsync().ConfigureAwait(false); if (!request.Headers.KeepAliveConnection() || context.Response.CloseConnection) { Client.Close(); } } UpdateLastOperationTime(); } else { Client.Close(); } } } catch (Exception e) { // Hate people who make bad calls. _logger?.Warn($"Error while serving : {_remoteEndPoint}", e); Client.Close(); } _logger?.Debug($"Lost Client {_remoteEndPoint}"); }