public void InitialEntriesCanBeCleared()
        {
            IDictionary<string, string[]> headers = new FrameResponseHeaders();

            headers.Clear();

            Assert.Equal(0, headers.Count);
            Assert.False(headers.ContainsKey("Server"));
            Assert.False(headers.ContainsKey("Date"));
        }
示例#2
0
 internal Enumerator(FrameResponseHeaders collection)
 {
     _collection        = collection;
     _bits              = collection._bits;
     _state             = 0;
     _current           = default(KeyValuePair <string, StringValues>);
     _hasUnknown        = collection.MaybeUnknown != null;
     _unknownEnumerator = _hasUnknown
         ? collection.MaybeUnknown.GetEnumerator()
         : default(Dictionary <string, StringValues> .Enumerator);
 }
        public void InitialDictionaryContainsServerAndDate()
        {
            IDictionary<string, string[]> headers = new FrameResponseHeaders();

            Assert.Equal(2, headers.Count);

            string[] serverHeader;
            Assert.True(headers.TryGetValue("Server", out serverHeader));
            Assert.Equal(1, serverHeader.Length);
            Assert.Equal("Kestrel", serverHeader[0]);

            string[] dateHeader;
            DateTime date;
            Assert.True(headers.TryGetValue("Date", out dateHeader));
            Assert.Equal(1, dateHeader.Length);
            Assert.True(DateTime.TryParse(dateHeader[0], out date));
            Assert.True(DateTime.Now - date <= TimeSpan.FromMinutes(1));

            Assert.False(headers.IsReadOnly);
        }
示例#4
0
        public void ProduceEnd(Exception ex)
        {
            if (ex != null)
            {
                if (_responseStarted)
                {
                    // We can no longer respond with a 500, so we simply close the connection.
                    ConnectionControl.End(ProduceEndType.SocketDisconnect);
                    return;
                }
                else
                {
                    StatusCode = 500;
                    ReasonPhrase = null;

                    // If OnStarting hasn't been triggered yet, we don't want to trigger it now that
                    // the app func has failed. https://github.com/aspnet/KestrelHttpServer/issues/43
                    _onStarting = null;

                    ResponseHeaders = new FrameResponseHeaders();
                    ResponseHeaders["Content-Length"] = new[] { "0" };
                }
            }

            ProduceStart(immediate: true, appCompleted: true);

            // _autoChunk should be checked after we are sure ProduceStart() has been called
            // since ProduceStart() may set _autoChunk to true.
            if (_autoChunk)
            {
                WriteChunkedResponseSuffix();
            }

            if (!_keepAlive)
            {
                ConnectionControl.End(ProduceEndType.SocketShutdownSend);
            }

            //NOTE: must finish reading request body
            ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketDisconnect);
        }