Skip to content

Commit

Permalink
Add some more common response headers to KnownHeaders (#34922)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Apr 14, 2020
1 parent ff01bf7 commit a5ff881
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal static class KnownHeaders
public static readonly KnownHeader Date = new KnownHeader("Date", HttpHeaderType.General | HttpHeaderType.NonTrailing, DateHeaderParser.Parser, null, H2StaticTable.Date, H3StaticTable.Date);
public static readonly KnownHeader ETag = new KnownHeader("ETag", HttpHeaderType.Response, GenericHeaderParser.SingleValueEntityTagParser, null, H2StaticTable.ETag, H3StaticTable.ETag);
public static readonly KnownHeader Expect = new KnownHeader("Expect", HttpHeaderType.Request | HttpHeaderType.NonTrailing, GenericHeaderParser.MultipleValueNameValueWithParametersParser, new string[] { "100-continue" }, H2StaticTable.Expect);
public static readonly KnownHeader ExpectCT = new KnownHeader("Expect-CT");
public static readonly KnownHeader Expires = new KnownHeader("Expires", HttpHeaderType.Content | HttpHeaderType.NonTrailing, DateHeaderParser.Parser, null, H2StaticTable.Expires);
public static readonly KnownHeader From = new KnownHeader("From", HttpHeaderType.Request, GenericHeaderParser.MailAddressParser, null, H2StaticTable.From);
public static readonly KnownHeader Host = new KnownHeader("Host", HttpHeaderType.Request | HttpHeaderType.NonTrailing, GenericHeaderParser.HostParser, null, H2StaticTable.Host);
Expand All @@ -69,6 +70,7 @@ internal static class KnownHeaders
public static readonly KnownHeader PublicKeyPins = new KnownHeader("Public-Key-Pins");
public static readonly KnownHeader Range = new KnownHeader("Range", HttpHeaderType.Request | HttpHeaderType.NonTrailing, GenericHeaderParser.RangeParser, null, H2StaticTable.Range, H3StaticTable.RangeBytes0ToAll);
public static readonly KnownHeader Referer = new KnownHeader("Referer", HttpHeaderType.Request, UriHeaderParser.RelativeOrAbsoluteUriParser, null, H2StaticTable.Referer, H3StaticTable.Referer); // NB: The spelling-mistake "Referer" for "Referrer" must be matched.
public static readonly KnownHeader ReferrerPolicy = new KnownHeader("Referrer-Policy");
public static readonly KnownHeader Refresh = new KnownHeader("Refresh", H2StaticTable.Refresh);
public static readonly KnownHeader RetryAfter = new KnownHeader("Retry-After", HttpHeaderType.Response | HttpHeaderType.NonTrailing, GenericHeaderParser.RetryConditionParser, null, H2StaticTable.RetryAfter);
public static readonly KnownHeader SecWebSocketAccept = new KnownHeader("Sec-WebSocket-Accept");
Expand All @@ -93,13 +95,15 @@ internal static class KnownHeaders
public static readonly KnownHeader WWWAuthenticate = new KnownHeader("WWW-Authenticate", HttpHeaderType.Response | HttpHeaderType.NonTrailing, GenericHeaderParser.MultipleValueAuthenticationParser, null, H2StaticTable.WwwAuthenticate);
public static readonly KnownHeader Warning = new KnownHeader("Warning", HttpHeaderType.General | HttpHeaderType.NonTrailing, GenericHeaderParser.MultipleValueWarningParser);
public static readonly KnownHeader XAspNetVersion = new KnownHeader("X-AspNet-Version");
public static readonly KnownHeader XCache = new KnownHeader("X-Cache");
public static readonly KnownHeader XContentDuration = new KnownHeader("X-Content-Duration");
public static readonly KnownHeader XContentTypeOptions = new KnownHeader("X-Content-Type-Options", http3StaticTableIndex: H3StaticTable.XContentTypeOptionsNoSniff);
public static readonly KnownHeader XFrameOptions = new KnownHeader("X-Frame-Options", http3StaticTableIndex: H3StaticTable.XFrameOptionsDeny);
public static readonly KnownHeader XMSEdgeRef = new KnownHeader("X-MSEdge-Ref");
public static readonly KnownHeader XPoweredBy = new KnownHeader("X-Powered-By");
public static readonly KnownHeader XRequestID = new KnownHeader("X-Request-ID");
public static readonly KnownHeader XUACompatible = new KnownHeader("X-UA-Compatible");
public static readonly KnownHeader XXssProtection = new KnownHeader("X-XSS-Protection");

// Helper interface for making GetCandidate generic over strings, utf8, etc
private interface IHeaderNameAccessor
Expand Down Expand Up @@ -209,6 +213,7 @@ public BytePtrAccessor(byte* p, int length)
case 'T': case 't': return Trailer; // [T]railer
case 'U': case 'u': return Upgrade; // [U]pgrade
case 'W': case 'w': return Warning; // [W]arning
case 'X': case 'x': return XCache; // [X]-Cache
}
break;

Expand All @@ -221,6 +226,13 @@ public BytePtrAccessor(byte* p, int length)
}
break;

case 9:
switch (key[0])
{
case 'E': case 'e': return ExpectCT; // [E]xpect-CT
}
break;

case 10:
switch (key[0])
{
Expand Down Expand Up @@ -282,6 +294,7 @@ public BytePtrAccessor(byte* p, int length)
case 'E': case 'e': return AcceptEncoding; // Accept-[E]ncoding
case 'K': case 'k': return PublicKeyPins; // Public-[K]ey-Pins
case 'L': case 'l': return AcceptLanguage; // Accept-[L]anguage
case 'R': case 'r': return ReferrerPolicy; // Referre[r]-Policy
}
break;

Expand All @@ -291,7 +304,13 @@ public BytePtrAccessor(byte* p, int length)
case 'O': case 'o': return ContentEncoding; // Content-Enc[o]ding
case 'G': case 'g': return ContentLanguage; // Content-Lan[g]uage
case 'A': case 'a': return ContentLocation; // Content-Loc[a]tion
case 'C': case 'c': return ProxyConnection; // Proxy-Conne[c]tion
case 'C': case 'c':
switch (key[0])
{
case 'P': case 'p': return ProxyConnection; // [P]roxy-Conne[c]tion
case 'X': case 'x': return XXssProtection; // [X]-XSS-Prote[c]tion
}
break;
case 'I': case 'i': return WWWAuthenticate; // WWW-Authent[i]cate
case 'R': case 'r': return XAspNetVersion; // X-AspNet-Ve[r]sion
}
Expand Down

0 comments on commit a5ff881

Please sign in to comment.