Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit 7f96eab

Browse files
committed
#381 handle known headers with no value.
1 parent 6ee0186 commit 7f96eab

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

shared/Microsoft.AspNetCore.HttpSys.Sources/RequestProcessing/NativeRequestContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private string GetKnowHeaderHelper(HttpSysRequestHeader header, long fixup, Http
259259
HttpApiTypes.HTTP_KNOWN_HEADER* pKnownHeader = (&request->Headers.KnownHeaders) + headerIndex;
260260
// For known headers, when header value is empty, RawValueLength will be 0 and
261261
// pRawValue will point to empty string ("\0")
262-
if (pKnownHeader->pRawValue != null)
262+
if (pKnownHeader->RawValueLength > 0)
263263
{
264264
value = HeaderEncoding.GetString(pKnownHeader->pRawValue + fixup, pKnownHeader->RawValueLength);
265265
}

test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/Listener/RequestHeaderTests.cs

+51
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Linq;
56
using System.Net.Http;
67
using System.Net.Sockets;
78
using System.Text;
@@ -93,6 +94,56 @@ public async Task RequestHeaders_ClientSendsUtf8Headers_Success()
9394
}
9495
}
9596

97+
[ConditionalFact]
98+
public async Task RequestHeaders_ClientSendsKnownHeaderWithNoValue_Success()
99+
{
100+
string address;
101+
using (var server = Utilities.CreateHttpServer(out address))
102+
{
103+
string[] customValues = new string[] { "" };
104+
Task responseTask = SendRequestAsync(address, "If-None-Match", customValues);
105+
106+
var context = await server.AcceptAsync(Utilities.DefaultTimeout);
107+
var requestHeaders = context.Request.Headers;
108+
Assert.Equal(3, requestHeaders.Count);
109+
Assert.Equal(new Uri(address).Authority, requestHeaders["Host"]);
110+
Assert.Equal(new[] { new Uri(address).Authority }, requestHeaders.GetValues("Host"));
111+
Assert.Equal("close", requestHeaders["Connection"]);
112+
Assert.Equal(new[] { "close" }, requestHeaders.GetValues("Connection"));
113+
Assert.Equal(StringValues.Empty, requestHeaders["If-None-Match"]);
114+
Assert.Empty(requestHeaders.GetValues("If-None-Match"));
115+
Assert.Equal("spacervalue", requestHeaders["Spacer-Header"]);
116+
context.Dispose();
117+
118+
await responseTask;
119+
}
120+
}
121+
122+
[ConditionalFact]
123+
public async Task RequestHeaders_ClientSendsUnknownHeaderWithNoValue_Success()
124+
{
125+
string address;
126+
using (var server = Utilities.CreateHttpServer(out address))
127+
{
128+
string[] customValues = new string[] { "" };
129+
Task responseTask = SendRequestAsync(address, "Custom-Header", customValues);
130+
131+
var context = await server.AcceptAsync(Utilities.DefaultTimeout);
132+
var requestHeaders = context.Request.Headers;
133+
Assert.Equal(4, requestHeaders.Count);
134+
Assert.Equal(new Uri(address).Authority, requestHeaders["Host"]);
135+
Assert.Equal(new[] { new Uri(address).Authority }, requestHeaders.GetValues("Host"));
136+
Assert.Equal("close", requestHeaders["Connection"]);
137+
Assert.Equal(new[] { "close" }, requestHeaders.GetValues("Connection"));
138+
Assert.Equal("", requestHeaders["Custom-Header"]);
139+
Assert.Empty(requestHeaders.GetValues("Custom-Header"));
140+
Assert.Equal("spacervalue", requestHeaders["Spacer-Header"]);
141+
context.Dispose();
142+
143+
await responseTask;
144+
}
145+
}
146+
96147
private async Task<string> SendRequestAsync(string uri)
97148
{
98149
using (HttpClient client = new HttpClient())

0 commit comments

Comments
 (0)