Inheritance: System.EventArgs
コード例 #1
0
        private void ProcessRequest(object sender, HttpRequestEventArgs e)
        {
            try
            {
                var request = new RackRequest();
                var response = new RackResponse(e.RequestContext.Response.OutputStream);

                PrepareRackRequest(e.RequestContext.Request, request);
                _rack.HandleRequest(request, response);

                response.Status = response.Status;
                foreach (var header in response.Headers)
                    if (header.Key.ToLower() != "content-length") //Cannot set directly
                        e.RequestContext.Response.Headers.Add(header.Key, header.Value);

                
            }
            catch (HttpListenerException)
            {
                return;
            }
            catch (Exception ex)
            {
                RequestProcessingError(this, new HttpRequestErrorEventArgs(e.RequestContext,ex));
                var writer = new StreamWriter(e.RequestContext.Response.OutputStream);
                writer.Write(ex.ToString());
                writer.Flush();
                
            }
        }
コード例 #2
0
        private void RaiseIncomingRequest(HttpListenerContext context)
        {
            var e = new HttpRequestEventArgs(context);

            if (IncomingRequest != null)
            {
                Action async = () =>
                                   {
                                       try
                                       {
                                           IncomingRequest(this, e);
                                           context.Response.Close();
                                       }
                                       catch (Exception ex)
                                       {
                                           RequestHandlingError(this, new HttpRequestErrorEventArgs(context, ex));
                                       }
                                   };
                async.BeginInvoke(null, null);
            }

        }