public void ProcessRequest(HttpContext aspNetContext) { Connection con = new Connection(aspNetContext.Response.OutputStream, aspNetContext.Request.UserHostAddress, 0); // Construct a copy of the HttpRequest.Headers collection, because the one created by ASP.NET // is automagically modified whenever the response collection created by ASP.NET is modified. // There is no good way to mimic this behavior when running in our own web server, so to // maintain compatibility with our own server we use a copy of the ASP.NET request headers // so they won't be modified when we add to the response headers. NameValueCollection requestHeaders = new NameValueCollection(); NameValueCollection aspNetRequestHeaders = aspNetContext.Request.Headers; foreach (string headerName in aspNetRequestHeaders) { foreach (string value in aspNetRequestHeaders.GetValues(headerName)) { requestHeaders.Add(headerName, value); } } WebRequest request = new WebRequest(aspNetContext.Request.RequestType, requestHeaders, aspNetContext.Request.RawUrl, aspNetContext.Request.Path, aspNetContext.Request.QueryString, con.RemoteAddress); for (int fileIndex = 0; fileIndex < aspNetContext.Request.Files.Count; fileIndex++) { string fieldName = aspNetContext.Request.Files.AllKeys[fileIndex]; HttpPostedFile aspNetFile = aspNetContext.Request.Files[fileIndex]; WebUploadedFile file = new WebUploadedFile(aspNetFile.FileName, aspNetFile.InputStream, aspNetFile.ContentLength, aspNetFile.ContentType); request.UploadedFiles.Add(fieldName, file); } WebResponse response = new WebResponse(con, aspNetContext.Response.Headers, aspNetContext.Response.Cookies, false); TSiteData siteData = (TSiteData)aspNetContext.Application[ AspNetHttpModule <TSiteData, TSession> .SiteDataKey]; WebSessionContainer <TSession> sessionContainer = siteData.GetSessionContainer(request, response); WebContext <TSiteData, TSession> webContext = new WebContext <TSiteData, TSession>( request, response, new ServerUtilities(new NullDiagOutput()), new SiteUtilities(aspNetContext.Server), siteData, sessionContainer.Session); WebPage <TSiteData, TSession> page = PageFactory.GetInstance(webContext); page.Process(webContext); }
public void ExecuteRequest(WebRequest request, WebResponse response, WebPortListener server) { WebSessionContainer <TSession> sessionContainer = _SiteData.GetSessionContainer(request, response); TSession session = sessionContainer.Session; WebContext <TSiteData, TSession> context = new WebContext <TSiteData, TSession>(request, response, server, new SiteUtilities(_SiteRoot), _SiteData, session); server.WriteDiagMessage(context.Request.Verb + " " + context.Request.RequestURI); IWebPageFactory <TSiteData, TSession> matchingHandler = null; foreach (IWebPageHandler <TSiteData, TSession> handler in _WebPageHandlers) { if (handler.IsMatch(context.Request.AbsoluteUriPath)) { matchingHandler = handler.Factory; break; } } if (matchingHandler == null) { throw new WebExceptions.ResourceNotFound(request.RequestURI); } switch (context.Request.Verb) { case HttpVerbs.Get: WebPage <TSiteData, TSession> getPage = matchingHandler.GetInstance(context); getPage.Process(context); response.FlushBody(server); break; case HttpVerbs.Head: WebPage <TSiteData, TSession> headPage = matchingHandler.GetInstance(context); headPage.Process(context); break; case HttpVerbs.Post: WebPage <TSiteData, TSession> postPage = matchingHandler.GetInstance(context); postPage.Process(context); response.FlushBody(server); break; default: throw new WebExceptions.NotImplemented("Verb " + context.Request.Verb + " not supported"); } }
public WebPage <TSiteData, TSession> GetInstance(WebContext <TSiteData, TSession> context) { string path = context.WebSiteInfo.MapPath(context.Request.AbsoluteUriPath); TXmlDocument xmlData; try { xmlData = _XmlDocuments.Get(path); } catch (System.IO.FileNotFoundException) { throw new WebExceptions.ResourceNotFound(context.Request.RequestURI); } XmlBasePage <TSiteData, TSession, TXmlDocument> page = GetXmlPageInstance(context, xmlData); page.SetXmlDocument(xmlData); return(page); }
/// <summary> /// Return the XmlBasePage to use. For example, extract a type identifier /// from xmlData and create an instance of that type. /// </summary> /// <param name="context"></param> /// <param name="xmlData"></param> /// <returns></returns> abstract public XmlBasePage <TSiteData, TSession, TXmlDocument> GetXmlPageInstance(WebContext <TSiteData, TSession> context, TXmlDocument xmlData);
public WebPage <TSiteData, TSession> GetInstance(WebContext <TSiteData, TSession> context) { return(new DebugPage <TSiteData, TSession>()); }
public WebPage <TSiteData, TSession> GetInstance(WebContext <TSiteData, TSession> context) { return(new StaticFilePage <TSiteData, TSession>(_ContentType)); }
/// <summary> /// Produce the output for the web page. /// Must set HTTP response headers and HTTP status, generally by calling /// context.Response.SetStdHeaders(). Then write the HTTP response body, /// generally by creating and using an IBodyWriter though you may directly /// call context.Response.WriteBody() if you like. All response headers /// MUST be set before the first data is written to the response body, /// because the response headers will be written to the response stream /// the first time data is written to the response body. /// </summary> /// <param name="context"></param> public abstract void Process(WebContext <TSiteData, TSession> context);
override public void Process(WebContext <TSiteData, TSession> context) { WebRequest request = context.Request; if (request.QueryArgs["force_error"] != null) { throw new Exception("Forced exception"); } StringBuilder content = new StringBuilder(); context.WebServerUtilities.WriteDiagMessage("Executing Debugpage.Initialize()"); content.Append(WebResponse.XHTML10_Doctype); content.Append(WebResponse.XHTML10_Html); content.Append(WebResponse.StandardErrorHead("Diagnostic Page")); content.AppendLine("<body>"); content.AppendLine("Verb " + WebResponse.HtmlEncode(request.Verb) + "<br/>"); content.AppendLine("URL [" + WebResponse.HtmlEncode(request.RequestURI) + "]<br/>"); content.AppendLine("Path [" + WebResponse.HtmlEncode(request.AbsoluteUriPath) + "]<br/>"); content.AppendLine("Query Args:<br/>"); WriteNameValueCollection(content, request.QueryArgs); content.AppendLine("Post Vars:<br/>"); WriteNameValueCollection(content, request.PostVars); content.AppendLine("Request Headers:<br/>"); foreach (string headerName in request.Headers) { foreach (string headerValue in request.Headers.GetValues(headerName)) { content.AppendLine(" " + headerName + ": [" + WebResponse.HtmlEncode(headerValue) + "]<br/>"); } } content.AppendLine("Uploaded Files:<br/>"); foreach (KeyValuePair <string, WebUploadedFile> pair in request.UploadedFiles) { content.AppendLine(" [name=" + WebResponse.HtmlEncode(pair.Key) + ";file=" + WebResponse.HtmlEncode(pair.Value.FileName) + ";type=" + WebResponse.HtmlEncode(pair.Value.ContentType) + ";Length=" + pair.Value.Length.ToString() + "]<br/>"); } content.AppendLine("Request Cookies:<br/>"); foreach (string cookieName in request.Cookies) { HttpCookie cookie = request.Cookies[cookieName]; content.AppendLine(" [" + WebResponse.HtmlEncode(cookie.Name) + "]=[" + WebResponse.HtmlEncode(cookie.Value) + "]<br/>"); } AppendMore(context, content); content.AppendLine("</body>"); content.AppendLine("</html>"); context.Response.SetStdHeaders(request.KeepAlive, ContentTypes.XHTML, content.Length); string setCookieName = context.Request.QueryArgs["cookie-name"]; if (setCookieName != null) { string setCookieValue = context.Request.QueryArgs["cookie-value"]; HttpCookie setCookie = new HttpCookie(setCookieName, setCookieValue); string setCookieMinutesText = context.Request.QueryArgs["cookie-minutes"]; if (setCookieMinutesText != null) { double setCookieMinutes; if (double.TryParse(setCookieMinutesText, out setCookieMinutes)) { setCookie.Expires = DateTime.Now.AddMinutes(setCookieMinutes); } } string setCookieDomain = context.Request.QueryArgs["cookie-domain"]; if (setCookieDomain != null) { setCookie.Domain = setCookieDomain; } string setCookiePath = context.Request.QueryArgs["cookie-path"]; if (setCookiePath != null) { setCookie.Path = setCookiePath; } context.Response.Cookies.Add(setCookie); } _BodyWriter = new TextBodyWriter(content.ToString()); _BodyWriter.WriteBody(context.Response, context.WebServerUtilities); }
/// <summary> /// Subclasses can override this method to output strongly typed TApplication and TSession information /// by casting "context" to the correct WebContext<TApplication, TSession> type. /// </summary> /// <param name="context"></param> /// <param name="content"></param> public virtual void AppendMore(WebContext <TSiteData, TSession> context, StringBuilder content) { }