1 // Copyright 2013 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_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_
10 #include "base/strings/string_piece.h"
11 #include "net/base/net_export.h"
12 #include "net/websockets/websocket_extension.h"
16 class NET_EXPORT_PRIVATE WebSocketExtensionParser
{
18 WebSocketExtensionParser();
19 ~WebSocketExtensionParser();
21 // Parses the given string as a WebSocket extension header value.
22 // This parser assumes some preprocesses are made.
23 // - The parser parses single extension at a time. This means that
24 // the parser parses |extension| in RFC6455 9.1, not |extension-list|.
25 // - There is no newline characters in the input. LWS-concatenation must
26 // have already been done.
27 void Parse(const char* data
, size_t size
);
28 void Parse(const std::string
& data
) {
29 Parse(data
.data(), data
.size());
32 bool has_error() const { return has_error_
; }
33 const WebSocketExtension
& extension() const { return extension_
; }
37 void ConsumeExtension(WebSocketExtension
* extension
);
38 void ConsumeExtensionParameter(WebSocketExtension::Parameter
* parameter
);
39 void ConsumeToken(base::StringPiece
* token
);
40 void ConsumeQuotedToken(std::string
* token
);
42 bool Lookahead(char c
);
43 bool ConsumeIfMatch(char c
);
44 size_t UnconsumedBytes() const { return end_
- current_
; }
46 static bool IsControl(char c
);
47 static bool IsSeparator(char c
);
52 WebSocketExtension extension_
;
54 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser
);
59 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_