Skip to content

Commit 07bd63c

Browse files
committed
Add end-to-end test
1 parent bfb1666 commit 07bd63c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
using Microsoft.AspNetCore.Connections;
1515
using Microsoft.AspNetCore.Http;
1616
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
17+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
1718
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
1819
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
1920
using Microsoft.AspNetCore.Testing;
2021
using Microsoft.Extensions.Logging;
22+
using Microsoft.Extensions.Primitives;
2123
using Microsoft.Net.Http.Headers;
2224
using Moq;
2325
using Xunit;
@@ -1906,6 +1908,79 @@ await ExpectAsync(Http2FrameType.HEADERS,
19061908
await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false);
19071909
}
19081910

1911+
[Fact]
1912+
public async Task HEADERS_ResponseSetsIgnoreIndexAndNeverIndexValues_HeadersParsed()
1913+
{
1914+
await InitializeConnectionAsync(c =>
1915+
{
1916+
c.Response.ContentLength = 0;
1917+
c.Response.Headers[HeaderNames.SetCookie] = "SetCookie!";
1918+
c.Response.Headers[HeaderNames.ContentDisposition] = "ContentDisposition!";
1919+
1920+
return Task.CompletedTask;
1921+
});
1922+
1923+
await StartStreamAsync(1, _browserRequestHeaders, endStream: true);
1924+
1925+
var frame = await ExpectAsync(Http2FrameType.HEADERS,
1926+
withLength: 90,
1927+
withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM),
1928+
withStreamId: 1);
1929+
1930+
var payload = frame.Payload;
1931+
1932+
var handler = new TestHttpHeadersHandler();
1933+
1934+
var hpackDecoder = new HPackDecoder();
1935+
hpackDecoder.Decode(new ReadOnlySequence<byte>(payload), endHeaders: true, handler);
1936+
hpackDecoder.CompleteDecode();
1937+
1938+
await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
1939+
1940+
Assert.Equal("200", handler.Headers[":status"]);
1941+
Assert.Equal("SetCookie!", handler.Headers[HeaderNames.SetCookie]);
1942+
Assert.Equal("ContentDisposition!", handler.Headers[HeaderNames.ContentDisposition]);
1943+
Assert.Equal("0", handler.Headers[HeaderNames.ContentLength]);
1944+
}
1945+
1946+
private class TestHttpHeadersHandler : IHttpHeadersHandler
1947+
{
1948+
public readonly Dictionary<string, StringValues> Headers = new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
1949+
1950+
public void OnHeader(ReadOnlySpan<byte> name, ReadOnlySpan<byte> value)
1951+
{
1952+
var nameString = Encoding.ASCII.GetString(name);
1953+
var valueString = Encoding.ASCII.GetString(value);
1954+
1955+
if (Headers.TryGetValue(nameString, out var values))
1956+
{
1957+
var l = values.ToList();
1958+
l.Add(valueString);
1959+
1960+
Headers[nameString] = new StringValues(l.ToArray());
1961+
}
1962+
else
1963+
{
1964+
Headers[nameString] = new StringValues(valueString);
1965+
}
1966+
}
1967+
1968+
public void OnHeadersComplete(bool endStream)
1969+
{
1970+
throw new NotImplementedException();
1971+
}
1972+
1973+
public void OnStaticIndexedHeader(int index)
1974+
{
1975+
throw new NotImplementedException();
1976+
}
1977+
1978+
public void OnStaticIndexedHeader(int index, ReadOnlySpan<byte> value)
1979+
{
1980+
throw new NotImplementedException();
1981+
}
1982+
}
1983+
19091984
[Fact]
19101985
public async Task HEADERS_DisableDynamicHeaderCompression_HeadersNotCompressed()
19111986
{

0 commit comments

Comments
 (0)