public static For ( string httpVersion, StringValues>.IDictionary |
||
httpVersion | string | |
headers | StringValues>.IDictionary | |
context | ||
return |
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);
}
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); }