protected override bool Process(IInteraction parameters) { HttpInteraction interaction = (HttpInteraction)parameters.GetClosest(typeof(HttpInteraction)); string mimeType; if (MimeType.Length > 0) { if (this.CharSet.Length > 0) { mimeType = string.Format( "{0}; charset={1}", this.MimeType, this.CharSet); } else { mimeType = this.MimeType; } interaction.SetContentType(mimeType); } interaction.SetStatusCode(this.Statuscode); return(WithBranch.TryProcess(parameters)); }
protected override bool Process(IInteraction parameters) { bool success = true; HttpInteraction interaction = (HttpInteraction)parameters.GetClosest(typeof(HttpInteraction)); string method = interaction.RequestMethod; if (IsMethodValid(method)) { success &= Branches [method.ToLower()].TryProcess(parameters); } else { interaction.SetStatusCode(405); } return(success); }
/// <summary> /// Enters the tree, onwards! /// </summary> /// <param name="context">Context.</param> void EnterTree(HttpListenerContext context) { HttpInteraction parameters = new HttpInteraction( context.Request, context.Response); try { if (Process(parameters)) { parameters.FlushBuffer(); } else { context.Response.StatusCode = 500; } } catch (Exception ex) { Secretary.Report(5, "Unhandled fault occurred near the server", ex.Message); Secretary.Report(7, ex.ToString()); } try { parameters.IncomingBody.Close(); } catch (Exception ex) { Secretary.Report(5, "Failure to close incoming stream", ex.Message); } try { parameters.OutgoingBody.Close(); } catch (Exception ex) { Secretary.Report(5, "Failure to close outgoing stream", ex.Message); } }