Beispiel #1
0
        public void ProcessRequest(IAsyncResult result)
        {
            if (_isDisposed)
            {
                return;
            }
            HttpListenerContext nativeContext;

            try
            {
                nativeContext = _listener.EndGetContext(result);
            }
            catch (HttpListenerException)
            {
                return;
            }
            QueueNextRequestPending();
            var ambientContext = new AmbientContext();
            var context        = new HttpListenerCommunicationContext(this, nativeContext);

            try
            {
                using (new ContextScope(ambientContext))
                {
                    IncomingRequestReceived(this, new IncomingRequestReceivedEventArgs(context));
                }
            }
            finally
            {
                using (new ContextScope(ambientContext))
                {
                    IncomingRequestProcessed(this, new IncomingRequestProcessedEventArgs(context));
                }
            }
        }
 public void ProcessRequest(IAsyncResult result)
 {
     if (_isDisposed)
         return;
     HttpListenerContext nativeContext;
     try
     {
         nativeContext = _listener.EndGetContext(result);
     }
     catch (HttpListenerException)
     {
         return;
     }
     QueueNextRequestPending();
     var ambientContext = new AmbientContext();
     var context = new HttpListenerCommunicationContext(this, nativeContext);
     try
     {
         using (new ContextScope(ambientContext))
         {
             IncomingRequestReceived(this, new IncomingRequestReceivedEventArgs(context));
         }
     }
     finally
     {
         using (new ContextScope(ambientContext))
         {
             IncomingRequestProcessed(this, new IncomingRequestProcessedEventArgs(context));
         }
     }
 }
        async Task ProcessContext()
        {
            QueueNextRequestPending();
            HttpListenerContext nativeContext;

            try
            {
                nativeContext = await _listener.GetContextAsync();
            }
            catch (HttpListenerException)
            {
                return;
            }
            var ambientContext = new AmbientContext();
            var context        = new HttpListenerCommunicationContext(this, nativeContext);

            try
            {
                using (new ContextScope(ambientContext))
                {
                    var incomingRequestReceivedEventArgs = new IncomingRequestReceivedEventArgs(context);
                    IncomingRequestReceived(this, incomingRequestReceivedEventArgs);
                    await incomingRequestReceivedEventArgs.RunTask;
                }
            }
            finally
            {
                using (new ContextScope(ambientContext))
                {
                    IncomingRequestProcessed(this, new IncomingRequestProcessedEventArgs(context));
                }
            }
        }
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context        = context;
     _nativeResponse = response;
     Headers         = new HttpHeaderDictionary();
     Entity          = new HttpEntity(Headers, response.OutputStream);
 }
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context = context;
     _nativeResponse = response;
     Headers = new HttpHeaderDictionary();
     Entity = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     this.context = context;
     this.nativeResponse = response;
     this.Headers = new HttpHeaderDictionary();
     this.Entity = new HttpEntity(this.Headers, this.tempStream);
     this.nativeResponse.SendChunked = false;
 }
Beispiel #7
0
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context                    = context;
     _nativeResponse             = response;
     Headers                     = new HttpHeaderDictionary();
     Entity                      = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
Beispiel #8
0
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context        = context;
     _nativeResponse = response;
     Headers         = new HttpHeaderDictionary();
     // TODO: Wrap stream and send chunked when needed if write starts before sending response
     Entity = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context = context;
     _nativeResponse = response;
     Headers = new HttpHeaderDictionary();
     // TODO: Wrap stream and send chunked when needed if write starts before sending response
     Entity = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
        public HttpListenerRequest(HttpListenerCommunicationContext context, System.Net.HttpListenerRequest request)
        {
            _context = context;
            _nativeRequest = request;
            Uri = _nativeRequest.Url;
            CodecParameters = new List<string>();

            Headers = new HttpHeaderDictionary(_nativeRequest.Headers);

            Entity = new HttpEntity(Headers, new HistoryStream(_nativeRequest.InputStream));

            if (!string.IsNullOrEmpty(_nativeRequest.ContentType))
                Entity.ContentType = new MediaType(_nativeRequest.ContentType);
        }
        public HttpListenerRequest(HttpListenerCommunicationContext context, System.Net.HttpListenerRequest request)
        {
            _context        = context;
            _nativeRequest  = request;
            Uri             = _nativeRequest.Url;
            CodecParameters = new List <string>();

            Headers = new HttpHeaderDictionary(_nativeRequest.Headers);

            Entity = new HttpEntity(Headers, _nativeRequest.InputStream);

            if (!string.IsNullOrEmpty(_nativeRequest.ContentType))
            {
                Entity.ContentType = new MediaType(_nativeRequest.ContentType);
            }
        }
        async Task ProcessContext(HttpListenerContext nativeContext)
        {
            var ambientContext = new AmbientContext();
            var context        = new HttpListenerCommunicationContext(this, nativeContext, Resolver.Resolve <ILogger>());

            try
            {
                Interlocked.Increment(ref _pendingRequestCount);
                _zeroPendingRequests.Reset();

                try
                {
                    using (new ContextScope(ambientContext))
                    {
                        Resolver.AddDependencyInstance(typeof(HttpListenerContext), nativeContext);
                        var incomingRequestReceivedEventArgs = new IncomingRequestReceivedEventArgs(context);
                        IncomingRequestReceived(this, incomingRequestReceivedEventArgs);
                        await incomingRequestReceivedEventArgs.RunTask;
                    }
                }
                finally
                {
                    using (new ContextScope(ambientContext))
                    {
                        IncomingRequestProcessed(this, new IncomingRequestProcessedEventArgs(context));
                    }
                }
            }
            finally
            {
                if (Interlocked.Decrement(ref _pendingRequestCount) == 0)
                {
                    _zeroPendingRequests.Set();
                }

                nativeContext.Response.Close();
            }
        }