Ejemplo n.º 1
0
		internal HttpRequest(HttpClient client)
		{
			dataMode = DataMode.Text;
			state = ProcessingState.RequestLine;
			connMode = ConnectionMode.KeepAlive;
			this.client = client;
			response = new HttpResponse(this);
		}
Ejemplo n.º 2
0
		internal ResponseEventArgs(HttpClient client, HttpResponse response, long contentLength) : base(client)
		{
			this.response = response;
			this.contentLength = contentLength;
		}
Ejemplo n.º 3
0
		internal ResponseEventArgs(HttpClient client, HttpResponse response) : this(client, response, -1)
		{
		}
Ejemplo n.º 4
0
		internal RequestEventArgs(HttpClient client, HttpRequest request) : base(client)
		{
			this.request = request;
		}
Ejemplo n.º 5
0
		/// <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;
		}
Ejemplo n.º 6
0
		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
			{
			}
		}
Ejemplo n.º 7
0
		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;
			}
		}