Add HTTP/2 pseudo headers as known headers (#19457)
This commit is contained in:
parent
0321390211
commit
41a3c63bc5
File diff suppressed because it is too large
Load Diff
|
|
@ -187,7 +187,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
// CONNECT - :scheme and :path must be excluded
|
// CONNECT - :scheme and :path must be excluded
|
||||||
if (Method == HttpMethod.Connect)
|
if (Method == HttpMethod.Connect)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(RequestHeaders[HeaderNames.Scheme]) || !String.IsNullOrEmpty(RequestHeaders[HeaderNames.Path]))
|
if (!String.IsNullOrEmpty(HttpRequestHeaders.HeaderScheme) || !String.IsNullOrEmpty(HttpRequestHeaders.HeaderPath))
|
||||||
{
|
{
|
||||||
ResetAndAbort(new ConnectionAbortedException(CoreStrings.Http2ErrorConnectMustNotSendSchemeOrPath), Http2ErrorCode.PROTOCOL_ERROR);
|
ResetAndAbort(new ConnectionAbortedException(CoreStrings.Http2ErrorConnectMustNotSendSchemeOrPath), Http2ErrorCode.PROTOCOL_ERROR);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -206,16 +206,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
// - That said, we shouldn't allow arbitrary values or use them to populate Request.Scheme, right?
|
// - That said, we shouldn't allow arbitrary values or use them to populate Request.Scheme, right?
|
||||||
// - For now we'll restrict it to http/s and require it match the transport.
|
// - For now we'll restrict it to http/s and require it match the transport.
|
||||||
// - We'll need to find some concrete scenarios to warrant unblocking this.
|
// - We'll need to find some concrete scenarios to warrant unblocking this.
|
||||||
if (!string.Equals(RequestHeaders[HeaderNames.Scheme], Scheme, StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(HttpRequestHeaders.HeaderScheme, Scheme, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
ResetAndAbort(new ConnectionAbortedException(
|
ResetAndAbort(new ConnectionAbortedException(
|
||||||
CoreStrings.FormatHttp2StreamErrorSchemeMismatch(RequestHeaders[HeaderNames.Scheme], Scheme)), Http2ErrorCode.PROTOCOL_ERROR);
|
CoreStrings.FormatHttp2StreamErrorSchemeMismatch(HttpRequestHeaders.HeaderScheme, Scheme)), Http2ErrorCode.PROTOCOL_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// :path (and query) - Required
|
// :path (and query) - Required
|
||||||
// Must start with / except may be * for OPTIONS
|
// Must start with / except may be * for OPTIONS
|
||||||
var path = RequestHeaders[HeaderNames.Path].ToString();
|
var path = HttpRequestHeaders.HeaderPath.ToString();
|
||||||
RawTarget = path;
|
RawTarget = path;
|
||||||
|
|
||||||
// OPTIONS - https://tools.ietf.org/html/rfc7540#section-8.1.2.3
|
// OPTIONS - https://tools.ietf.org/html/rfc7540#section-8.1.2.3
|
||||||
|
|
@ -252,7 +252,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
private bool TryValidateMethod()
|
private bool TryValidateMethod()
|
||||||
{
|
{
|
||||||
// :method
|
// :method
|
||||||
_methodText = RequestHeaders[HeaderNames.Method].ToString();
|
_methodText = HttpRequestHeaders.HeaderMethod.ToString();
|
||||||
Method = HttpUtilities.GetKnownMethod(_methodText);
|
Method = HttpUtilities.GetKnownMethod(_methodText);
|
||||||
|
|
||||||
if (Method == HttpMethod.None)
|
if (Method == HttpMethod.None)
|
||||||
|
|
@ -278,7 +278,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
// :authority (optional)
|
// :authority (optional)
|
||||||
// Prefer this over Host
|
// Prefer this over Host
|
||||||
|
|
||||||
var authority = RequestHeaders[HeaderNames.Authority];
|
var authority = HttpRequestHeaders.HeaderAuthority;
|
||||||
var host = HttpRequestHeaders.HeaderHost;
|
var host = HttpRequestHeaders.HeaderHost;
|
||||||
if (!StringValues.IsNullOrEmpty(authority))
|
if (!StringValues.IsNullOrEmpty(authority))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ namespace CodeGenerator
|
||||||
{
|
{
|
||||||
var requestPrimaryHeaders = new[]
|
var requestPrimaryHeaders = new[]
|
||||||
{
|
{
|
||||||
|
":authority",
|
||||||
|
":method",
|
||||||
|
":path",
|
||||||
|
":scheme",
|
||||||
"Accept",
|
"Accept",
|
||||||
"Connection",
|
"Connection",
|
||||||
"Host",
|
"Host",
|
||||||
|
|
@ -72,6 +76,10 @@ namespace CodeGenerator
|
||||||
};
|
};
|
||||||
RequestHeaders = commonHeaders.Concat(new[]
|
RequestHeaders = commonHeaders.Concat(new[]
|
||||||
{
|
{
|
||||||
|
":authority",
|
||||||
|
":method",
|
||||||
|
":path",
|
||||||
|
":scheme",
|
||||||
"Accept",
|
"Accept",
|
||||||
"Accept-Charset",
|
"Accept-Charset",
|
||||||
"Accept-Encoding",
|
"Accept-Encoding",
|
||||||
|
|
@ -247,7 +255,7 @@ namespace CodeGenerator
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public string Identifier => Name.Replace("-", "");
|
public string Identifier => ResolveIdentifier(Name);
|
||||||
|
|
||||||
public byte[] Bytes => Encoding.ASCII.GetBytes($"\r\n{Name}: ");
|
public byte[] Bytes => Encoding.ASCII.GetBytes($"\r\n{Name}: ");
|
||||||
public int BytesOffset { get; set; }
|
public int BytesOffset { get; set; }
|
||||||
|
|
@ -264,6 +272,21 @@ namespace CodeGenerator
|
||||||
public string SetBit() => $"_bits |= {"0x" + (1L << Index).ToString("x")}L";
|
public string SetBit() => $"_bits |= {"0x" + (1L << Index).ToString("x")}L";
|
||||||
public string ClearBit() => $"_bits &= ~{"0x" + (1L << Index).ToString("x")}L";
|
public string ClearBit() => $"_bits &= ~{"0x" + (1L << Index).ToString("x")}L";
|
||||||
|
|
||||||
|
private string ResolveIdentifier(string name)
|
||||||
|
{
|
||||||
|
var identifer = name.Replace("-", "");
|
||||||
|
|
||||||
|
// Pseudo headers start with a colon. A colon isn't valid in C# names so
|
||||||
|
// remove it and pascal case the header name. e.g. :path -> Path, :scheme -> Scheme.
|
||||||
|
// This identifier will match the names in HeadersNames.cs
|
||||||
|
if (identifer.StartsWith(':'))
|
||||||
|
{
|
||||||
|
identifer = char.ToUpper(identifer[1]) + identifer.Substring(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return identifer;
|
||||||
|
}
|
||||||
|
|
||||||
private void GetMaskAndComp(string name, int offset, int count, out ulong mask, out ulong comp)
|
private void GetMaskAndComp(string name, int offset, int count, out ulong mask, out ulong comp)
|
||||||
{
|
{
|
||||||
mask = 0;
|
mask = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue