1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_STATUS_LINE_VALIDATOR_H_
6 #define NET_HTTP_HTTP_STATUS_LINE_VALIDATOR_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string_piece.h"
12 #include "net/base/net_export.h"
16 class HttpStatusLineValidator
{
19 // status-line = HTTP-version SP status-code SP reason-phrase CRLF
20 // status-code = 3DIGIT
21 // reason-phrase = *( HTAB / SP / VCHAR / obs-text )
22 // And from RFC 7230 S2.6:
23 // HTTP-version = HTTP-name "/" DIGIT "." DIGIT
24 // HTTP-name = "\x48\x54\x54\x50" ; ie, "HTTP" in uppercase
25 enum StatusLineStatus
{
26 // No violations found.
29 STATUS_LINE_EMPTY
= 1,
31 STATUS_LINE_NOT_HTTP
= 2,
33 STATUS_LINE_HTTP_CASE_MISMATCH
= 3,
35 STATUS_LINE_HTTP_NO_VERSION
= 4,
36 // "HTTP/abc" or "HTTP/1" or "HTTP/1."
37 STATUS_LINE_INVALID_VERSION
= 5,
39 STATUS_LINE_MULTI_DIGIT_VERSION
= 6,
41 STATUS_LINE_UNKNOWN_VERSION
= 7,
43 STATUS_LINE_EXPLICIT_0_9
= 8,
45 STATUS_LINE_MISSING_STATUS_CODE
= 9,
47 STATUS_LINE_INVALID_STATUS_CODE
= 10,
49 STATUS_LINE_STATUS_CODE_TRAILING
= 11,
50 // "HTTP/1.1 404", note that "HTTP/1.1 404 " is a valid empty reason phrase
51 STATUS_LINE_MISSING_REASON_PHRASE
= 12,
52 // "HTTP/1.1 200 \x01"
53 STATUS_LINE_REASON_DISALLOWED_CHARACTER
= 13,
55 STATUS_LINE_EXCESS_WHITESPACE
= 14,
57 STATUS_LINE_RESERVED_STATUS_CODE
= 15,
62 // Checks for violations of the RFC 7230 S3.1.2 status-line grammar, and
63 // returns the first violation found, or STATUS_LINE_OK if the status line
65 static StatusLineStatus NET_EXPORT_PRIVATE
ValidateStatusLine(
66 const base::StringPiece
& status_line
);
69 static StatusLineStatus
CheckHttpVersionSyntax(
70 const base::StringPiece
& version
);
71 static StatusLineStatus
CheckStatusCodeSyntax(
72 const base::StringPiece
& status_code
);
73 // Checks |fields| against the reason-phrase syntax in RFC 7230 S3.1.2, ie:
74 // reason-phrase = *( HTAB / SP / VCHAR / obs-text )
75 // Note that the HTTP stream parser ignores the reason-phrase entirely, so
76 // this check is needlessly pedantic.
77 static StatusLineStatus
CheckReasonPhraseSyntax(
78 const std::vector
<base::StringPiece
>& fields
,
81 DISALLOW_IMPLICIT_CONSTRUCTORS(HttpStatusLineValidator
);
86 #endif // NET_HTTP_HTTP_STATUS_LINE_VALIDATOR_H_