protected override bool Process(IInteraction parameters) { IHttpInteraction httpInteraction = Closest <IHttpInteraction> .From(parameters); string contentType; if (this.ContentType.Length > 0) { contentType = this.ContentType; } else { contentType = Fallback <string> .From(parameters, "contenttype"); }; httpInteraction.SetContentType(contentType); if (this.SendLength) { long length = Fallback <long> .From(parameters, "contentlength"); httpInteraction.SetContentLength(length); } httpInteraction.PurgeBuffer(); return(WithBranch.TryProcess(parameters)); }
protected override bool Process(IInteraction parameters) { bool success = true; IInteraction uncastParameters; IHttpInteraction httpParameters = null; string requestedPath = RootPath; string coreUrl = ""; if (parameters.TryGetClosest(typeof(IHttpInteraction), out uncastParameters) && UseHttp) { httpParameters = (IHttpInteraction)uncastParameters; string[] urlArray = httpParameters.URL.ToArray(); coreUrl = string.Join("/", urlArray); string decodedPathFromURL = HttpUtility.UrlDecode(Path.Combine(urlArray)); requestedPath = Path.Combine(requestedPath, decodedPathFromURL); } DirectoryInfo requestedInfo = new DirectoryInfo(requestedPath); if (requestedInfo.Exists) { FilesystemItemInteraction itemInteraction = new FilesystemItemInteraction(parameters, RootPath, coreUrl); foreach (DirectoryInfo info in requestedInfo.GetDirectories()) { itemInteraction.Assume(info); success &= directoryItem.TryProcess(itemInteraction); } foreach (FileInfo info in requestedInfo.GetFiles()) { itemInteraction.Assume(info); success &= fileItem.TryProcess(itemInteraction); } } else { httpParameters.SetStatusCode(404); success &= dirNotFound.TryProcess(httpParameters); } return(success); }
protected override bool Process(IInteraction parameters) { /* return "Basic " + Convert.ToBase64String ( * Encoding.ASCII.GetBytes ( * string.Format ( * "{0}:{1}", * Username, * Password * ) * ) * ); */ bool successful = true; IHttpInteraction httpParameters = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction)); string authHeader = httpParameters.RequestHeaders["Authorization"]; if ((authHeader != null) && authHeader.StartsWith("Basic ")) { string encAuthString = authHeader.Substring("Basic ".Length).Trim(); string authString = Encoding.ASCII.GetString(Convert.FromBase64String(encAuthString)); string[] userPass = authString.Split(':'); if (userPass.Length == 2) { var credentials = new SimpleInteraction(); credentials ["username"] = userPass [0]; credentials ["password"] = userPass [1]; successful &= Successful.TryProcess(credentials); } else { successful &= Failure.TryProcess(parameters); } } else { httpParameters.SetStatusCode(401); httpParameters.ResponseHeaders ["WWW-Authenticate"] = ResponseHeader; successful &= Failure.TryProcess(parameters); } return(successful); }
/// <summary> /// Initializes a new instance of the <see cref="BorrehSoft.Extensions.Navigation.SubsectionInteraction"/> class. /// </summary> /// <param name="http">Http.</param> /// <param name="parent">Parent.</param> public RouteInteraction(IHttpInteraction http, IInteraction parent, string resourceNameKey) : base(parent) { this.ParentHttp = http; this.ResourceNameKey = resourceNameKey; this [this.ResourceNameKey] = "main"; // Directoryname is legacy! this ["directoryname"] = "main"; HasTail = http.URL.Count > 0; if (HasTail) { this [this.ResourceNameKey] = http.URL.Peek(); this ["directoryname"] = http.URL.Peek(); } }
protected override bool Process(IInteraction parameters) { IHttpInteraction httpParameters = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction)); string authHeader = httpParameters.RequestHeaders["Authorization"]; bool successful = true; if ((authHeader != null) && (authHeader == LoginString)) { successful &= Successful.TryProcess(parameters); } else { httpParameters.SetStatusCode(401); httpParameters.ResponseHeaders ["WWW-Authenticate"] = ResponseHeader; successful &= Failure.TryProcess(parameters); } return(successful); }
protected override bool Process(IInteraction parameters) { IHttpInteraction httpParameters = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction)); string[] urlArray = httpParameters.URL.ToArray(); string decodedPathFromURL = HttpUtility.UrlDecode(Path.Combine(urlArray)); while (decodedPathFromURL.ToLower().EndsWith(".tar")) { decodedPathFromURL = decodedPathFromURL.Remove(decodedPathFromURL.Length - 4); } string requestedPath = Path.Combine(RootPath, decodedPathFromURL); httpParameters.ResponseHeaders ["Content-Type"] = "application/tar"; ProcessStartInfo pStart = new ProcessStartInfo(TarCommand, "-cO ."); pStart.WorkingDirectory = requestedPath; pStart.RedirectStandardOutput = true; pStart.UseShellExecute = false; Proc p = Proc.Start(pStart); bool success = false; try { p.StandardOutput.BaseStream.CopyTo(httpParameters.OutgoingBody); success = true; } catch (Exception ex) { Secretary.Report(5, "Tarring for", requestedPath, " failed with message ", ex.Message); } if (!success) { p.StandardOutput.Close(); p.Kill(); p.Dispose(); } return(success); }
protected override bool Process(IInteraction uncastParameters) { IHttpInteraction httpParameters = (IHttpInteraction)uncastParameters.GetClosest( typeof(IHttpInteraction)); RouteInteraction interaction = new RouteInteraction( httpParameters, uncastParameters, this.ResourceNameKey); Service branch = Stub; if (branch == Stub) { branch = Branches [interaction.DirectoryName] ?? Stub; } if (branch == Stub) { branch = Branches ["continue"]; } if (branch == Stub) { branch = Branches [SingleBranchNames.With]; } if (branch == Stub) { branch = Branches ["default"]; } else { interaction.Confirm(); } return(branch.TryProcess(interaction)); }
public override string AcquireData(IInteraction parameters) { IHttpInteraction request = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction)); return(request.GetQuery); }
protected override bool Process(IInteraction parameters) { bool successful = true; IInteraction httpInteractionCandidate; if (successful = parameters.TryGetClosest(typeof(IHttpInteraction), out httpInteractionCandidate)) { IHttpInteraction httpInteraction = (IHttpInteraction)httpInteractionCandidate; if (httpInteraction.ContentType.StartsWith(MimeTypePrefix)) { string headerBoundary = httpInteraction.ContentType.Substring(MimeTypePrefix.Length); SimpleInteraction mappedValues = new SimpleInteraction(parameters); StreamingMultipartFormDataParser parser = new StreamingMultipartFormDataParser( httpInteraction.IncomingBody, headerBoundary, httpInteraction.Encoding, this.BufferSize ); parser.ParameterHandler += delegate(ParameterPart part) { if (this.StringFieldWhiteList.Contains(part.Name)) { mappedValues[part.Name] = part.Data; successful &= this.Branches.Get(part.Name, Stub).TryProcess( new WwwInputInteraction(part.Name, part.Data, parameters) ); } }; parser.FileHandler += delegate( string name, string fileName, string contentType, string contentDisposition, byte[] buffer, int bytes ) { if (this.StringFieldWhiteList.Contains(name)) { MemoryStream stream = new MemoryStream(buffer, 0, bytes); SimpleIncomingInteraction incoming = new SimpleIncomingInteraction( stream, mappedValues, contentDisposition, contentType ); incoming ["mimetype"] = contentType; incoming ["filename"] = fileName; successful &= this.Branches.Get(name, Stub).TryProcess(incoming); stream.Dispose(); } }; parser.Run(); successful &= this.Mapped.TryProcess(mappedValues); } else { Secretary.Report(5, "Require boundary content type for multipart forms"); successful &= Failure.TryProcess(parameters); } } else { Secretary.Report(5, "Require HttpInteraction for multipart forms"); successful &= Failure.TryProcess(parameters); } return(successful); }