|
14 | 14 | using Microsoft.AspNetCore.Connections;
|
15 | 15 | using Microsoft.AspNetCore.Http;
|
16 | 16 | using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
| 17 | +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; |
17 | 18 | using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
|
18 | 19 | using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
19 | 20 | using Microsoft.AspNetCore.Testing;
|
20 | 21 | using Microsoft.Extensions.Logging;
|
| 22 | +using Microsoft.Extensions.Primitives; |
21 | 23 | using Microsoft.Net.Http.Headers;
|
22 | 24 | using Moq;
|
23 | 25 | using Xunit;
|
@@ -1906,6 +1908,79 @@ await ExpectAsync(Http2FrameType.HEADERS,
|
1906 | 1908 | await StopConnectionAsync(expectedLastStreamId: 3, ignoreNonGoAwayFrames: false);
|
1907 | 1909 | }
|
1908 | 1910 |
|
| 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 | + |
1909 | 1984 | [Fact]
|
1910 | 1985 | public async Task HEADERS_DisableDynamicHeaderCompression_HeadersNotCompressed()
|
1911 | 1986 | {
|
|
0 commit comments