internal HttpRequest(HttpClient client) { dataMode = DataMode.Text; state = ProcessingState.RequestLine; connMode = ConnectionMode.KeepAlive; this.client = client; response = new HttpResponse(this); }
internal ResponseEventArgs(HttpClient client, HttpResponse response, long contentLength) : base(client) { this.response = response; this.contentLength = contentLength; }
internal ResponseEventArgs(HttpClient client, HttpResponse response) : this(client, response, -1) { }
internal RequestEventArgs(HttpClient client, HttpRequest request) : base(client) { this.request = request; }
/// <summary> /// Creates a new <see cref="ClientEventArgs"/> with the specified client. /// </summary> /// <param name="client">The client to which the event belongs.</param> public ClientEventArgs(HttpClient client) { this.client = client; }
internal void OnRequestReceived(HttpClient client, HttpRequest request) { try { RequestEventArgs args = new RequestEventArgs(client, request); if(RequestReceived != null) RequestReceived(this, args); if(request.IsValidRequest) { if(logRequests) //BUG: Uri.ToString() decodes a url encoded string for a second time; % disappears Log.WriteLine("Request: " + client.RemoteAddress + " " + request.Uri); if(ValidRequestReceived != null) ValidRequestReceived(this, args); } else { if(InvalidRequestReceived != null) InvalidRequestReceived(this, args); } } finally { } }
void DoListen() { try { while(!stop) { HttpClient client; try { client = new HttpClient(listener.AcceptSocket(), this); } catch(IOException) { continue; } catch(SocketException) { continue; } client.Disconnected += new EventHandler(client_Disconnected); if(ClientConnected != null) ClientConnected(this, new ClientEventArgs(client)); if(logConnections) Log.WriteLine("Connected: " + client.RemoteAddress); } } #if !DEBUG catch(SocketException e) { Log.WriteLine("Error: " + e.ToString()); } #endif finally { stop = false; listener.Stop(); listener = null; isRunning = false; } }