Ejemplo n.º 1
0
 public override void OnRequest(Request request, Response response)
 {
     if (this.IsHardRewrite)
     {
         this.TargetResource.OnRequest(request, response);
     }
     else
     {
         response.Headers.Add("Location", this.target.ToString());
     }
 }
Ejemplo n.º 2
0
 public override void OnRequest(Request request, Response response)
 {
     if (File.Exists(this.location))
     {
         //TODO: Fix this so it works with large files.
         response.Write(File.ReadAllBytes(this.location));
     }
     else
     {
         //ErrorHandler.Handle(StatusCode.Http404NotFound);
     }
 }
Ejemplo n.º 3
0
        public override sealed void OnRequest(Request request, Response response)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                Document form = this.CreateForm();

                RenderingContext rc = new RenderingContext(ms);
                rc.Request = request;
                rc.Response = response;
                form.Render(rc);

                response.Write(ms.ToArray());
            }
        }
Ejemplo n.º 4
0
        public override void OnRequest(Request request, Response response)
        {
            base.OnRequest(request, response);

            var doc = new XDocument(
                new XElement("html",
                 new XElement("head",
                     new XElement("title", "Serenity: Login"),
                //new XElement("link",
                //    new XAttribute("rel", "stylesheet"),
                //    new XAttribute("type", "text/css"),
                //    new XAttribute("href", DirectoryResource.StylesheetUrl))),
                 new XElement("body",
                     new XElement("form",
                         new XAttribute("method", "get"),
                         //new XAttribute("action", this.Binding.Path),
                         new XAttribute("enctype", "multipart/form-data"),
                         new XText("Username: "******"input",
                             new XAttribute("type", "username"),
                             new XAttribute("name", "username")),
                             new XText("Password: "******"input",
                             new XAttribute("type", "password"),
                             new XAttribute("name", "password")),
                            new XElement("input",
                                new XAttribute("type", "submit"),
                                new XAttribute("name", "submit"),
                                new XAttribute("value", "Login")))))));

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.ConformanceLevel = ConformanceLevel.Document;
            settings.Encoding = Encoding.UTF8;
            settings.Indent = true;

            // output data
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(ms, settings))
                {
                    doc.Save(writer);
                    writer.Flush();
                    writer.Close();
                }
                response.Write(ms.ToArray());
            }
            response.ContentType = MimeType.TextHtml;
            response.IsComplete = true;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpServerAsyncState"/>
        /// class.
        /// </summary>
        /// <param name="connection">The <see cref="Socket"/> representing the connection with the remote client.</param>
        public HttpServerAsyncState(Socket connection)
        {
            Contract.Requires(connection != null);

            this.connection = connection;
            this.buffer = new NetworkBuffer();
            this.rawRequest = new StringBuilder();
            this.currentToken = new StringBuilder();
            this.stage = HttpRequestParseStep.Method;
            this.request = new Request()
            {
                Connection = this.Connection
            };
            this.response = new Response()
            {
                Connection = this.Connection
            };
        }
Ejemplo n.º 6
0
 public void OnRequest(Request request, Response response)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
 public override void OnRequest(Request request, Response response)
 {
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Overridden. Renders the dynamic content of the current DirectoryResource.
        /// </summary>
        /// <param name="request">The incoming <see cref="Request"/>.</param>
        /// <param name="response">The outgoing <see cref="Response"/>.</param>
        public override void OnRequest(Request request, Response response)
        {
            if (response.IsComplete)
                return;

            Uri uri = this.GetRelativeUri();

            // collect data for index generation
            SortedDictionary<ResourceGrouping, List<Resource>> groupedResources = new SortedDictionary<ResourceGrouping, List<Resource>>();
            if (this.Locations.Count > 0)
                foreach (var res in from n in this.Locations[0]
                                    where n.Resource != null
                                    select n.Resource)
                {
                    if (!groupedResources.ContainsKey(res.Grouping))
                    {
                        groupedResources.Add(res.Grouping, new List<Resource>());
                    }
                    groupedResources[res.Grouping].Add(res);
                }

            string host = request.UserHostName ?? "localhost";

            //string host = uri.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped);

            var doc = new XDocument(new XElement("html",
                new XElement("head",
                    new XElement("title", string.Format(Theme.DirectoryTitle, uri.ToString())),
                    new XElement("link",
                        new XAttribute("rel", "stylesheet"),
                        new XAttribute("type", "text/css"),
                        new XAttribute("href", DirectoryResource.StylesheetUrl))),
                new XElement("body",
                    new XElement("div",
                        new XAttribute("class", "main_heading"),
                        string.Format(Theme.DirectoryTitle, string.Empty),
                        new XElement("a",
                            new XAttribute("href", host), host),
                            "/"),
                        from g in groupedResources
                        orderby g.Key
                        select new XElement("div",
                            new XElement("div",
                                new XAttribute("class", "group_heading"),
                                g.Key.PluralForm),
                                new XElement("table", new XAttribute("class", "group"),
                                    new XElement("tr",
                                        new XElement("th",
                                            new XAttribute("class", "icon")),
                                            new XElement("th",
                                                new XAttribute("class", "name"),
                                                "Name"),
                                            new XElement("th",
                                                new XAttribute("class", "size"),
                                                "Size"),
                                            new XElement("th",
                                                new XAttribute("class", "description"),
                                                "Description"),
                                            new XElement("th",
                                                new XAttribute("class", "modified"),
                                                "Modified")),
                                from r in g.Value
                                orderby r.Name
                                select new XElement("tr",
                                    new XElement("td",
                                        new XElement("img",
                                            new XAttribute("src", "/serenity/icons/page_white.png"))),
                                    new XElement("td",
                                        new XElement("a",
                                            new XAttribute("href", r.GetAbsoluteUri(request.Url)),
                                            (r.Name.Length > 0) ? r.Name : "default")),
                                            new XElement("td",
                                                (r.Size < 0) ? "N/A" :
                                                (r.Size < 1024) ? r.Size.ToString("G") + "B" :
                                                (r.Size < 1048576) ? (r.Size / 1024F).ToString("G2") + "KB" :
                                                (r.Size < 1073741824) ? (r.Size / 1048576F).ToString("G2") + "MB" :
                                                (r.Size / 1073741824F).ToString("G2") + "GB"),
                                    new XElement("td",
                                        g.Key.SingularForm),
                                    new XElement("td",
                                        r.Modified.ToString("yyyy-MM-dd HH:mm:ss"))))))));

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.ConformanceLevel = ConformanceLevel.Document;
            settings.Encoding = Encoding.UTF8;
            settings.Indent = false;

            // output data
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(ms, settings))
                {
                    doc.Save(writer);
                    writer.Flush();
                    writer.Close();
                }
                response.Write(ms.ToArray());
            }
            response.ContentType = MimeType.TextHtml;
            response.IsComplete = true;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Validates a <see cref="Request"/> and determines if it meets the requirements of the HTTP specification.
 /// </summary>
 /// <param name="request"></param>
 /// <param name="response"></param>
 /// <returns></returns>
 /// <remarks>
 /// If the <see cref="Request"/> fails validation, the <see cref="Response"/> is modified with relevant information that notifies the client
 /// about the failed validation.
 /// </remarks>
 public abstract bool ValidateRequest(Request request, Response response);
Ejemplo n.º 10
0
 public override bool ValidateRequest(Request request, Response response)
 {
     // TODO: Implement basic request validation.
     return true;
 }
Ejemplo n.º 11
0
 public override void OnRequest(Request request, Response response)
 {
     byte[] data = new byte[this.stream.Length];
     this.stream.Position = 0;
     this.stream.Read(data, 0, data.Length);
     response.Write(data);
     response.Status = StatusCode.Http200Ok;
     response.ContentType = this.ContentType;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// When overridden in a derived class, uses the supplied CommonContext to dynamically generate response content.
 /// </summary>
 /// <param name="request"></param>
 /// <param name="response"></param>
 public virtual void OnRequest(Request request, Response response)
 {
     Contract.Requires(request != null);
     Contract.Requires(response != null);
 }
Ejemplo n.º 13
0
 public override void OnRequest(Request request, Response response)
 {
     base.OnRequest(request, response);
 }