diff options
Diffstat (limited to 'SocketHttpListener/Net/HttpListenerRequest.cs')
| -rw-r--r-- | SocketHttpListener/Net/HttpListenerRequest.cs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/SocketHttpListener/Net/HttpListenerRequest.cs b/SocketHttpListener/Net/HttpListenerRequest.cs index 6a99eb078..f9df52593 100644 --- a/SocketHttpListener/Net/HttpListenerRequest.cs +++ b/SocketHttpListener/Net/HttpListenerRequest.cs @@ -31,7 +31,7 @@ namespace SocketHttpListener.Net HttpListenerContext context; bool is_chunked; bool ka_set; - bool keep_alive; + bool? _keepAlive; private readonly ITextEncoding _textEncoding; @@ -525,29 +525,35 @@ namespace SocketHttpListener.Net { get { - if (ka_set) - return keep_alive; - - ka_set = true; - // 1. Connection header - // 2. Protocol (1.1 == keep-alive by default) - // 3. Keep-Alive header - string cnc = headers["Connection"]; - if (!String.IsNullOrEmpty(cnc)) + if (!_keepAlive.HasValue) { - keep_alive = (0 == String.Compare(cnc, "keep-alive", StringComparison.OrdinalIgnoreCase)); - } - else if (version == HttpVersion.Version11) - { - keep_alive = true; - } - else - { - cnc = headers["keep-alive"]; - if (!String.IsNullOrEmpty(cnc)) - keep_alive = (0 != String.Compare(cnc, "closed", StringComparison.OrdinalIgnoreCase)); + string header = Headers["Proxy-Connection"]; + if (string.IsNullOrEmpty(header)) + { + header = Headers["Connection"]; + } + if (string.IsNullOrEmpty(header)) + { + if (ProtocolVersion >= HttpVersion.Version11) + { + _keepAlive = true; + } + else + { + header = Headers["Keep-Alive"]; + _keepAlive = !string.IsNullOrEmpty(header); + } + } + else + { + header = header.ToLower(CultureInfo.InvariantCulture); + _keepAlive = + header.IndexOf("close", StringComparison.OrdinalIgnoreCase) < 0 || + header.IndexOf("keep-alive", StringComparison.OrdinalIgnoreCase) >= 0; + } } - return keep_alive; + + return _keepAlive.Value; } } |
