Microsoft.AspNet.Server.Kestrel.Http.MessageBody.For C# (CSharp) Method

For() public static method

public static For ( string httpVersion, StringValues>.IDictionary headers, FrameContext context ) : MessageBody
httpVersion string
headers StringValues>.IDictionary
context FrameContext
return MessageBody
        public static MessageBody For(
            string httpVersion,
            IDictionary<string, StringValues> headers,
            FrameContext context)
        {
            // see also http://tools.ietf.org/html/rfc2616#section-4.4

            var keepAlive = httpVersion != "HTTP/1.0";

            string connection;
            if (TryGet(headers, "Connection", out connection))
            {
                keepAlive = connection.Equals("keep-alive", StringComparison.OrdinalIgnoreCase);
            }

            string transferEncoding;
            if (TryGet(headers, "Transfer-Encoding", out transferEncoding))
            {
                return new ForChunkedEncoding(keepAlive, context);
            }

            string contentLength;
            if (TryGet(headers, "Content-Length", out contentLength))
            {
                return new ForContentLength(keepAlive, int.Parse(contentLength), context);
            }

            if (keepAlive)
            {
                return new ForContentLength(true, 0, context);
            }

            return new ForRemainingData(context);
        }

Usage Example

示例#1
0
 private void Execute()
 {
     MessageBody = MessageBody.For(
         HttpVersion,
         RequestHeaders,
         this);
     _keepAlive   = MessageBody.RequestKeepAlive;
     RequestBody  = new FrameRequestStream(MessageBody);
     ResponseBody = new FrameResponseStream(this);
     DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody);
     SocketInput.Free();
     Task.Run(ExecuteAsync);
 }
All Usage Examples Of Microsoft.AspNet.Server.Kestrel.Http.MessageBody::For