jgauffin / Griffin.WebServer

A web server built on top of Griffin.Framework
107 stars 42 forks source link

WebServer crashed because HTTP 1.0 #8

Closed dennyling closed 9 years ago

dennyling commented 11 years ago

My code as below

   // Module manager handles all modules in the server
   var moduleManager = new ModuleManager();

   moduleManager.Add(new BodyDecodingModule(new UrlFormattedDecoder()));
   MyModule myM = new MyModule();
   moduleManager.Add(myM);
   // And start the server.
   HttpServer _server = new HttpServer(moduleManager);                    
   _server.Start(IPAddress.Any, 8088);

  public class MyModule : IWorkerModule
 {
    public ModuleResult HandleRequest(IHttpContext context)
    {
        IRequest msg = context.Request;
        if (msg.Method == "GET")
        {
            byte[] byContent = Encoding.UTF8.GetBytes("welcome, my friend");
            context.Response.Body = new MemoryStream();
            context.Response.ContentType = "text/html; charset=UTF-8";
            context.Response.Body.Write(byContent, 0, byContent.Length);
            context.Response.Body.Position = 0;
        }
        else if (msg.Method == "POST")
        {
            if (msg.ContentLength > 0 && msg.Body != null)
            {
                var buff = new byte[msg.ContentLength];
                msg.Body.Read(buff, 0, msg.ContentLength);
                Encoding codeM = Encoding.GetEncoding("utf-8");
                string strContent = codeM.GetString(buff);
                OutputMessage(string.Format("Content:{0}", strContent));
            }
        }           
        return ModuleResult.Continue;
    }

}

My application was crashed after received one http request. Logger as below

Method:GET/ContentEncoding:/ContentLength:0 ProtocolVersion:HTTP/1.0/KeepAlive:True/ContentType: Uri AbsoluteUri:http://58.215.164.183/?signature=1dfea26808d632903549c69d78558fce1c418405&echostr=5867553698596935317&timestamp=1365661332&nonce=1366146317/AbsolutePath://Host:58.215.164.183/Port:80 QueryString/Name:signature/Value:1dfea26808d632903549c69d78558fce1c418405 QueryString/Name:echostr/Value:5867553698596935317 QueryString/Name:timestamp/Value:1365661332 QueryString/Name:nonce/Value:1366146317 Headers/Name:User-Agent/Value:Mozilla/4.0 Headers/Name:Accept/Value:/ Headers/Name:Host/Value:58.215.164.183 Headers/Name:Pragma/Value:no-cache Headers/Name:Connection/Value:Keep-Alive

jgauffin commented 11 years ago

close the issue and describe the changes for future readers.

dennyling commented 11 years ago

the issue still exist

jgauffin commented 11 years ago

Keep-alive is not valid for HTTP/1.0

jgauffin commented 9 years ago

I've taken another look at this and can currently not reproduce it.

I'm sending the following message over a plain socket to reproduce your case:

GET /?signature=1dfea26808d632903549c69d78558fce1c418405&echostr=5867553698596935317&timestamp=1365661332&nonce=1366146317 HTTP/1.0
ContentEncoding:
ContentLength:0
ContentType:
User-Agent:Mozilla 4.0
Accept: 
Name:Host
Value:58.215.164.183
Pragma:no-cache
Connection:Keep-Alive

If that's not the same as your message, leave the exact HTTP message as a comment.