public Handle ( |
||
context | ||
next | System.Action | |
Результат | void |
public void Handle(HttpListenerContext context, Action next) { _pipeline.Handle(context, next); }
private void HandleRequest(IAsyncResult ar) { try { var context = _listener.EndGetContext(ar); if (_listener.IsListening) { HandleNextRequest(); var req = context.Request; var res = context.Response; try { OnRequestBegin(new RequestEventArgs { Request = req, Response = res }); _anyRequestHandler.Handle(context, () => { IHttpResourceHandler handler; lock (_locker) { handler = _resourceHandlers.Where(h => h.HasParameterMatching).FirstOrDefault(h => h.Matches(req)) ?? _resourceHandlers .Where(h => !h.HasParameterMatching).FirstOrDefault(h => h.Matches(req)); } if (handler != null) { handler.Handle(context, () => { }); } else { res.StatusCode = 404; OnRequestUnhandled(new RequestEventArgs { Request = req, Response = res }); } OnRequestEnd(new RequestEventArgs { Request = req, Response = res }); }); res.Close(); } catch (Exception ex) { res.StatusCode = 500; OnRequestError(new RequestErrorEventArgs { Exception = ex, Request = req, Response = res }); Console.WriteLine(ex); using (var output = new StreamWriter(res.OutputStream)) { output.Write(ex); } res.Close(); } } } catch (HttpListenerException e) { if (!IsOperationAbortedOnStoppingServer(e)) { throw; } } catch (Exception e) { Console.WriteLine(e); } }