Skip to content

Commit 0240b1f

Browse files
Remove Pseudo-Headers From Public API (#42496)
1 parent a7ef863 commit 0240b1f

32 files changed

+1278
-1237
lines changed

src/Http/Headers/src/HeaderNames.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Microsoft.Net.Http.Headers;
1010
// Please do not open PRs without first opening an issue to discuss a specific item.
1111
public static class HeaderNames
1212
{
13+
private const string PseudoHeaderNamesObsoletionMessage = "This is obsolete and will be removed in a future version. Header dictionaries do not contain this key.";
14+
1315
// Use readonly statics rather than constants so ReferenceEquals works
1416

1517
/// <summary>Gets the <c>Accept</c> HTTP header name.</summary>
@@ -61,6 +63,7 @@ public static class HeaderNames
6163
public static readonly string AltSvc = "Alt-Svc";
6264

6365
/// <summary>Gets the <c>:authority</c> HTTP header name.</summary>
66+
[Obsolete(PseudoHeaderNamesObsoletionMessage, false)]
6467
public static readonly string Authority = ":authority";
6568

6669
/// <summary>Gets the <c>Authorization</c> HTTP header name.</summary>
@@ -178,20 +181,19 @@ public static class HeaderNames
178181
public static readonly string MaxForwards = "Max-Forwards";
179182

180183
/// <summary>Gets the <c>:method</c> HTTP header name.</summary>
184+
[Obsolete(PseudoHeaderNamesObsoletionMessage, false)]
181185
public static readonly string Method = ":method";
182186

183187
/// <summary>Gets the <c>Origin</c> HTTP header name.</summary>
184188
public static readonly string Origin = "Origin";
185189

186190
/// <summary>Gets the <c>:path</c> HTTP header name.</summary>
191+
[Obsolete(PseudoHeaderNamesObsoletionMessage, false)]
187192
public static readonly string Path = ":path";
188193

189194
/// <summary>Gets the <c>Pragma</c> HTTP header name.</summary>
190195
public static readonly string Pragma = "Pragma";
191196

192-
/// <summary>Gets the <c>Protocol</c> HTTP header name.</summary>
193-
public static readonly string Protocol = ":protocol";
194-
195197
/// <summary>Gets the <c>Proxy-Authenticate</c> HTTP header name.</summary>
196198
public static readonly string ProxyAuthenticate = "Proxy-Authenticate";
197199

@@ -214,6 +216,7 @@ public static class HeaderNames
214216
public static readonly string RequestId = "Request-Id";
215217

216218
/// <summary>Gets the <c>:scheme</c> HTTP header name.</summary>
219+
[Obsolete(PseudoHeaderNamesObsoletionMessage, false)]
217220
public static readonly string Scheme = ":scheme";
218221

219222
/// <summary>Gets the <c>Sec-WebSocket-Accept</c> HTTP header name.</summary>
@@ -238,6 +241,7 @@ public static class HeaderNames
238241
public static readonly string SetCookie = "Set-Cookie";
239242

240243
/// <summary>Gets the <c>:status</c> HTTP header name.</summary>
244+
[Obsolete(PseudoHeaderNamesObsoletionMessage, false)]
241245
public static readonly string Status = ":status";
242246

243247
/// <summary>Gets the <c>Strict-Transport-Security</c> HTTP header name.</summary>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
#nullable enable
2-
static readonly Microsoft.Net.Http.Headers.HeaderNames.Protocol -> string!

src/Middleware/HttpLogging/src/HttpLoggingOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public sealed class HttpLoggingOptions
8686
HeaderNames.LastModified,
8787
HeaderNames.Location,
8888
HeaderNames.Server,
89-
HeaderNames.Status,
9089
HeaderNames.TransferEncoding,
9190
HeaderNames.Upgrade,
9291
HeaderNames.XPoweredBy

src/Servers/HttpSys/test/FunctionalTests/Http2Tests.cs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.AspNetCore.Http;
1212
using Microsoft.AspNetCore.Http.Features;
1313
using Microsoft.AspNetCore.Http2Cat;
14+
using Microsoft.AspNetCore.Server;
1415
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2;
1516
using Microsoft.AspNetCore.Testing;
1617
using Microsoft.Extensions.Hosting;
@@ -48,7 +49,7 @@ public async Task EmptyResponse_200()
4849

4950
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
5051
{
51-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
52+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
5253
});
5354

5455
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -79,17 +80,17 @@ public async Task RequestWithoutData_LengthRequired_Rejected(string method)
7980

8081
var headers = new[]
8182
{
82-
new KeyValuePair<string, string>(HeaderNames.Method, method),
83-
new KeyValuePair<string, string>(HeaderNames.Path, "/"),
84-
new KeyValuePair<string, string>(HeaderNames.Scheme, "https"),
85-
new KeyValuePair<string, string>(HeaderNames.Authority, "localhost:80"),
83+
new KeyValuePair<string, string>(PseudoHeaderNames.Method, method),
84+
new KeyValuePair<string, string>(PseudoHeaderNames.Path, "/"),
85+
new KeyValuePair<string, string>(PseudoHeaderNames.Scheme, "https"),
86+
new KeyValuePair<string, string>(PseudoHeaderNames.Authority, "localhost:80"),
8687
};
8788

8889
await h2Connection.StartStreamAsync(1, headers, endStream: true);
8990

9091
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
9192
{
92-
Assert.Equal("411", decodedHeaders[HeaderNames.Status]);
93+
Assert.Equal("411", decodedHeaders[PseudoHeaderNames.Status]);
9394
});
9495

9596
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -129,17 +130,17 @@ public async Task RequestWithoutData_Success(string method)
129130

130131
var headers = new[]
131132
{
132-
new KeyValuePair<string, string>(HeaderNames.Method, method),
133-
new KeyValuePair<string, string>(HeaderNames.Path, "/"),
134-
new KeyValuePair<string, string>(HeaderNames.Scheme, "https"),
135-
new KeyValuePair<string, string>(HeaderNames.Authority, "localhost:80"),
133+
new KeyValuePair<string, string>(PseudoHeaderNames.Method, method),
134+
new KeyValuePair<string, string>(PseudoHeaderNames.Path, "/"),
135+
new KeyValuePair<string, string>(PseudoHeaderNames.Scheme, "https"),
136+
new KeyValuePair<string, string>(PseudoHeaderNames.Authority, "localhost:80"),
136137
};
137138

138139
await h2Connection.StartStreamAsync(1, headers, endStream: true);
139140

140141
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
141142
{
142-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
143+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
143144
});
144145

145146
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -179,10 +180,10 @@ public async Task RequestWithDataAndContentLength_Success(string method)
179180

180181
var headers = new[]
181182
{
182-
new KeyValuePair<string, string>(HeaderNames.Method, method),
183-
new KeyValuePair<string, string>(HeaderNames.Path, "/"),
184-
new KeyValuePair<string, string>(HeaderNames.Scheme, "https"),
185-
new KeyValuePair<string, string>(HeaderNames.Authority, "localhost:80"),
183+
new KeyValuePair<string, string>(PseudoHeaderNames.Method, method),
184+
new KeyValuePair<string, string>(PseudoHeaderNames.Path, "/"),
185+
new KeyValuePair<string, string>(PseudoHeaderNames.Scheme, "https"),
186+
new KeyValuePair<string, string>(PseudoHeaderNames.Authority, "localhost:80"),
186187
new KeyValuePair<string, string>(HeaderNames.ContentLength, "11"),
187188
};
188189

@@ -199,7 +200,7 @@ public async Task RequestWithDataAndContentLength_Success(string method)
199200

200201
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
201202
{
202-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
203+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
203204
});
204205

205206
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -244,10 +245,10 @@ public async Task RequestWithDataAndNoContentLength_Success(string method)
244245

245246
var headers = new[]
246247
{
247-
new KeyValuePair<string, string>(HeaderNames.Method, method),
248-
new KeyValuePair<string, string>(HeaderNames.Path, "/"),
249-
new KeyValuePair<string, string>(HeaderNames.Scheme, "https"),
250-
new KeyValuePair<string, string>(HeaderNames.Authority, "localhost:80"),
248+
new KeyValuePair<string, string>(PseudoHeaderNames.Method, method),
249+
new KeyValuePair<string, string>(PseudoHeaderNames.Path, "/"),
250+
new KeyValuePair<string, string>(PseudoHeaderNames.Scheme, "https"),
251+
new KeyValuePair<string, string>(PseudoHeaderNames.Authority, "localhost:80"),
251252
};
252253

253254
await h2Connection.StartStreamAsync(1, headers, endStream: false);
@@ -263,7 +264,7 @@ public async Task RequestWithDataAndNoContentLength_Success(string method)
263264

264265
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
265266
{
266-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
267+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
267268
});
268269

269270
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -298,7 +299,7 @@ public async Task ResponseWithData_Success()
298299

299300
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
300301
{
301-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
302+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
302303
});
303304

304305
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -336,7 +337,7 @@ await h2Connection.ReceiveHeadersAsync(1, endStream: true, decodedHeaders =>
336337
{
337338
// HTTP/2 filters out the connection header
338339
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
339-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
340+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
340341
});
341342

342343
// Send and receive a second request to ensure there is no GoAway frame on the wire yet.
@@ -347,7 +348,7 @@ await h2Connection.ReceiveHeadersAsync(3, endStream: true, decodedHeaders =>
347348
{
348349
// HTTP/2 filters out the connection header
349350
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
350-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
351+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
351352
});
352353

353354
await h2Connection.StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
@@ -383,7 +384,7 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
383384
{
384385
// HTTP/2 filters out the connection header
385386
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
386-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
387+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
387388
});
388389

389390
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -422,7 +423,7 @@ await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
422423
{
423424
// HTTP/2 filters out the connection header
424425
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
425-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
426+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
426427
});
427428

428429
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -462,7 +463,7 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
462463
{
463464
// HTTP/2 filters out the connection header
464465
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
465-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
466+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
466467
});
467468

468469
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -479,7 +480,7 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
479480
{
480481
// HTTP/2 filters out the connection header
481482
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
482-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
483+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
483484
});
484485

485486
dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -498,7 +499,7 @@ await h2Connection.ReceiveHeadersAsync(streamId, decodedHeaders =>
498499
{
499500
// HTTP/2 filters out the connection header
500501
Assert.False(decodedHeaders.ContainsKey(HeaderNames.Connection));
501-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
502+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
502503
});
503504

504505
dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -529,7 +530,7 @@ public async Task AppException_BeforeResponseHeaders_500()
529530

530531
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
531532
{
532-
Assert.Equal("500", decodedHeaders[HeaderNames.Status]);
533+
Assert.Equal("500", decodedHeaders[PseudoHeaderNames.Status]);
533534
});
534535

535536
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -562,7 +563,7 @@ public async Task AppException_AfterHeaders_PriorOSVersions_ResetCancel()
562563

563564
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
564565
{
565-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
566+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
566567
});
567568

568569
var resetFrame = await h2Connection.ReceiveFrameAsync();
@@ -594,7 +595,7 @@ public async Task AppException_AfterHeaders_ResetInternalError()
594595

595596
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
596597
{
597-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
598+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
598599
});
599600

600601
var frame = await h2Connection.ReceiveFrameAsync();
@@ -723,7 +724,7 @@ public async Task Reset_AfterResponseHeaders_Resets()
723724

724725
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
725726
{
726-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
727+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
727728
});
728729

729730
var resetFrame = await h2Connection.ReceiveFrameAsync();
@@ -770,7 +771,7 @@ public async Task Reset_DurringResponseBody_Resets()
770771

771772
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
772773
{
773-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
774+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
774775
});
775776

776777
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -822,7 +823,7 @@ public async Task Reset_AfterCompleteAsync_NoReset()
822823

823824
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
824825
{
825-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
826+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
826827
});
827828

828829
var dataFrame = await h2Connection.ReceiveFrameAsync();
@@ -975,7 +976,7 @@ public async Task Reset_CompleteAsyncDurringRequestBody_Resets()
975976

976977
await h2Connection.ReceiveHeadersAsync(1, decodedHeaders =>
977978
{
978-
Assert.Equal("200", decodedHeaders[HeaderNames.Status]);
979+
Assert.Equal("200", decodedHeaders[PseudoHeaderNames.Status]);
979980
});
980981

981982
var dataFrame = await h2Connection.ReceiveFrameAsync();

src/Servers/HttpSys/test/FunctionalTests/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<Compile Include="$(SharedSourceRoot)ValueTaskExtensions\**\*.cs" LinkBase="Shared\" />
2121
<Compile Remove="$(SharedSourceRoot)ServerInfrastructure\DuplexPipe.cs" />
2222
<Compile Remove="$(SharedSourceRoot)ServerInfrastructure\StringUtilities.cs" />
23+
<Compile Include="$(SharedSourceRoot)PseudoHeaderNames.cs" Linkbase="shared"/>
2324
<Compile Include="$(KestrelSharedSourceRoot)test\TestResources.cs" LinkBase="shared" />
2425
<Content Include="$(KestrelSharedSourceRoot)test\TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
2526
<Compile Include="$(KestrelSharedSourceRoot)test\TransportTestHelpers\MsQuicSupportedAttribute.cs" LinkBase="shared\" />

0 commit comments

Comments
 (0)