diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-07-01 12:24:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-01 12:24:26 -0400 |
| commit | ff3713153ad2317e1c196f33ac2cba61b449a00e (patch) | |
| tree | 84d2e6ed5bcb556a2395603b6403c8e992535e6b /SocketHttpListener/Net/HttpListenerRequest.cs | |
| parent | fad71a6c7d12c8b207cdf473c7dd7daafa53c174 (diff) | |
| parent | 2dcad6b5977f5c5be81b18c42506ed8ad3fb73b6 (diff) | |
Merge pull request #2739 from MediaBrowser/beta
Beta
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; } } |
