Inheritance: IHttpContext, IDisposable
Exemplo n.º 1
0
		private void ProcessRequest(HttpListenerContext context)
		{
			if (context == null)
				return;

			Task.Factory.StartNew(() =>
			{
				var ctx = new HttpListenerContextAdpater(context, SystemConfiguration, bufferPool);

				if (concurrentRequestSemaphore.Wait(TimeSpan.FromSeconds(5)) == false)
				{
					try
					{
						HandleTooBusyError(ctx);
					}
					catch (Exception e)
					{
						logger.WarnException("Could not send a too busy error to the client", e);
					}
					return;
				}
				try
				{
					Interlocked.Increment(ref physicalRequestsCount);
#if DEBUG
					recentRequests.Enqueue(ctx.Request.RawUrl);
					while (recentRequests.Count > 50)
					{
						string _;
						recentRequests.TryDequeue(out _);
					}
#endif

					if (ChangesQuery.IsMatch(ctx.GetRequestUrl()))
						HandleChangesRequest(ctx, () => { });
					else
						HandleActualRequest(ctx);
				}
				finally
				{
					concurrentRequestSemaphore.Release();
				}
			});
		}
Exemplo n.º 2
0
		private void GetContext(IAsyncResult ar)
		{
			HttpListenerContextAdpater ctx;
			try
			{
				HttpListenerContext httpListenerContext = listener.EndGetContext(ar);
				ctx = new HttpListenerContextAdpater(httpListenerContext, SystemConfiguration, bufferPool);
				//setup waiting for the next request
				listener.BeginGetContext(GetContext, null);
			}
			catch (Exception)
			{
				// can't get current request / end new one, probably
				// listener shutdown
				return;
			}

			if (concurrentRequestSemaphore.Wait(TimeSpan.FromSeconds(5)) == false)
			{
				HandleTooBusyError(ctx);
				return;
			}
			try
			{
				Interlocked.Increment(ref physicalRequestsCount);
				if (ChangesQuery.IsMatch(ctx.GetRequestUrl()))
					HandleChangesRequest(ctx, () => { });
				else
					HandleActualRequest(ctx);
			}
			finally
			{
				concurrentRequestSemaphore.Release();
			}
		}
Exemplo n.º 3
0
        private void GetContext(IAsyncResult ar)
        {
            IHttpContext ctx;
            try
            {
                ctx = new HttpListenerContextAdpater(listener.EndGetContext(ar), Configuration);
                //setup waiting for the next request
                listener.BeginGetContext(GetContext, null);
            }
            catch(InvalidOperationException)
            {
                // can't get current request / end new one, probably
                // listner shutdown
                return;
            }
            catch (HttpListenerException)
            {
                // can't get current request / end new one, probably
                // listner shutdown
                return;
            }

            if (concurretRequestSemaphore.Wait(TimeSpan.FromSeconds(5)) == false)
            {
                HandleTooBusyError(ctx);
                return;
            }
            try
            {
                HandleActualRequest(ctx);
            }
            finally
            {
                concurretRequestSemaphore.Release();
            }
        }
Exemplo n.º 4
0
		private void ProcessRequest(HttpListenerContext context)
		{
			IHttpContext ctx = new HttpListenerContextAdpater(context, new InMemoryRavenConfiguration
			{
				VirtualDirectory = "/"
			}, bufferPool);

			try
			{
				foreach (var responder in responders.Where(x => x.WillRespond(ctx)))
				{
					responder.Respond(ctx);
					return;
				}

				ctx.SetStatusToBadRequest();
			}
			catch (Exception)
			{
				ctx.SetStatusToBadRequest();
			}
			finally
			{
				ctx.FinalizeResponse();
			}
		}