private static void CheckValueFormat(string?value) { // Either value is null/empty or a valid token/quoted string https://tools.ietf.org/html/rfc7230#section-3.2.6 if (string.IsNullOrEmpty(value)) { return; } // Trailing/leading space are not allowed if (value.StartsWith(' ') || value.StartsWith('\t') || value.EndsWith(' ') || value.EndsWith('\t')) { ThrowFormatException(value); } if (value[0] == '"') { HttpParseResult parseResult = HttpRuleParser.GetQuotedStringLength(value, 0, out int valueLength); if (parseResult != HttpParseResult.Parsed || valueLength != value.Length) { ThrowFormatException(value); } } else if (HttpRuleParser.ContainsNewLine(value)) { ThrowFormatException(value); }
/// <summary> /// Allows for arbitrary header values without validation (aside from newline, which is always invalid in a header value). /// </summary> private static int ParseWithoutValidation(string value, int startIndex, out object?parsedValue) { if (HttpRuleParser.ContainsNewLine(value, startIndex)) { parsedValue = null; return(0); } string result = value.Substring(startIndex); parsedValue = result; return(result.Length); }