static HttpHeaderFactory()
        {
            dict = new Dictionary <string, Func <string, HttpHeader> >();

            dict.Add(HttpHeaderConnection.NAME.ToLowerInvariant(), (value) =>
            {
                return(new HttpHeaderConnection(value));
            });

            dict.Add(HttpHeaderContentLength.NAME.ToLowerInvariant(), (value) =>
            {
                return(new HttpHeaderContentLength(int.Parse(value)));
            });

            dict.Add(HttpHeaderContentType.NAME.ToLowerInvariant(), (value) =>
            {
                return(new HttpHeaderContentType(value));
            });

            dict.Add(HttpHeaderHost.NAME.ToLowerInvariant(), (value) =>
            {
                return(new HttpHeaderHost(value));
            });

            dict.Add(HttpHeaderTransferEncoding.NAME.ToLowerInvariant(), (value) =>
            {
                return(HttpHeaderTransferEncoding.Parse(value));
            });

            dict.Add(HttpHeaderUpgrade.NAME.ToLowerInvariant(), (value) =>
            {
                return(new HttpHeaderUpgrade(value));
            });
        }
Exemplo n.º 2
0
 protected void ParseMessageBody()
 {
     MessageBody = null;
     if (CanHaveMessageBody())
     {
         HttpHeaderTransferEncoding te = HeaderList.TransferEncoding;
         if (te != null)
         {
             if (te.IsChunked)
             {
                 ParseChunkedBody();
             }
             else
             {
                 throw new NotImplementedException(ERROR_UNSUPPORTED_TRANSFER_ENCODING);
             }
         }
         else
         {
             int length = HeaderList.ContentLength;
             if (length == 0)
             {
                 // no message-body assumed
             }
             else if (length > 0)
             {
                 MessageBody = new HttpSimpleMessageBody(ReadBySize(length));
             }
             else
             {
                 MessageBody = new HttpSimpleMessageBody(ReadToEOF());
             }
             OnReceiveBody?.Invoke();
         }
     }
     else
     {
         OnReceiveBody?.Invoke();
     }
 }