Beispiel #1
0
        public override string ToString()
        {
            var page = new HtmlPage()
            { 
                new HtmlElement("div", "content")
                {
                    new HtmlElement("div", "title")
                    {
                        new Text(((int)Code).ToString())
                    },                
                    new HtmlElement("div", "bottomtext")
                    {
                        new Text(Message)
                    },
                }
            };
            page.Head.Add(new HtmlElement("style")
            {
                new Text(
@"
    html {
        height: 100%;
    }
    * {
        text-align: center;
        font-family: Verdana, sans-serif;
    }
    body {
        height: 100%;
    }
    #content {
        position: relative;
        top: 25%;
    }
    #title {
        font-size: 80px
    }
")
            });
            var res = new HTTP.HttpPack(page.ToString());
            res.ContentType = page.ContentType;
            return res.ToString(Code);
        }
Beispiel #2
0
        public override void Process(HTTP.HttpServer server, HTTP.HttpPack pack, Socket client)
        {
            if (pack.Path == "/resource")
                sendResource(pack, client);
            var encoding = Encoding.UTF8;
            if (pack.Path == "/error")
            {
                int errorCode = 400;
                int.TryParse(pack.Request, out errorCode);
                if (errorCode != 404)
                    client.Send(encoding.GetBytes(new HTTP.ErrorPage((HTTP.ResponseCode)errorCode, ((HTTP.ResponseCode)errorCode).ToString().Replace('_', ' ')).ToString()));
            }
            if (pack.Path != "/" && pack.Path != "")
                client.Send(encoding.GetBytes(new HTTP.ErrorPage(HTTP.ResponseCode.NOT_FOUND, "Oops!").ToString()));
            int visitCount = 0;
            var t = pack.Cookies["visitcount"];
            if (t != null)
                int.TryParse(t.Value, out visitCount);
            visitCount++;
            var page = new HtmlPage()
            { 
                new HtmlElement("div", "content")
                {
                    new HtmlElement("div", "toptext") { new Text("if you see it, then") },
                    new HtmlElement("div", "title") { new Text("NiL.WBE") },
                    new HtmlElement("div", "bottomtext") { new Text("working") },
                    new Text("you was here " + visitCount + " times")
                }
            };
            page.Head.Add(new HtmlElement("style")
            {
                new Text(
@"
    html {
        height: 100%;
    }
    * {
        text-align: center;
        font-family: Lobster;
    }
    body {
        height: 100%;
    }
    #content {
        position: relative;
        top: 25%;
    }
    #title {
        font-size: 80px
    }
    @font-face {
        font-family: 'Lobster';
        font-style: normal;
        font-weight: 400;
        src: local('Lobster'), url(http://themes.googleusercontent.com/static/fonts/lobster/v5/9eID_a1kLfzp_BP9s4L15g.woff) format('woff');
    }
")
            });
            page.Head.Add(new HtmlElement("title") { new Text("NiL.WBE") });
            var res = new HTTP.HttpPack(page.ToString());
            res.ContentType = page.ContentType;
            res.Cookies.Add(new System.Net.Cookie("visitcount", visitCount.ToString()));
            client.Send(encoding.GetBytes(res.ToString(HTTP.ResponseCode.OK)));
            var connection = pack.Fields["connection"];
            if (string.Compare("keep-alive", connection, StringComparison.OrdinalIgnoreCase) == 0
                || (string.IsNullOrWhiteSpace(connection) && pack.Version == "HTTP/1.1"))
                return;
            client.Close();
        }