Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(787)

Unified Diff: net/websockets/websocket_extension_parser.h

Issue 1047623002: Support parsing a Sec-WebSocket-Extensions header with multiple elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clear extensions_ if errored Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/websockets/websocket_extension_parser.h
diff --git a/net/websockets/websocket_extension_parser.h b/net/websockets/websocket_extension_parser.h
index ef7fe0366575c696f039008d4989246f6b5b43a2..4899f37065ce302cc69a088b7265d90c75421e08 100644
--- a/net/websockets/websocket_extension_parser.h
+++ b/net/websockets/websocket_extension_parser.h
@@ -6,6 +6,7 @@
#define NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_
#include <string>
+#include <vector>
#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
@@ -18,19 +19,21 @@ class NET_EXPORT_PRIVATE WebSocketExtensionParser {
WebSocketExtensionParser();
~WebSocketExtensionParser();
- // Parses the given string as a WebSocket extension header value.
- // This parser assumes some preprocesses are made.
- // - The parser parses single extension at a time. This means that
- // the parser parses |extension| in RFC6455 9.1, not |extension-list|.
- // - There is no newline characters in the input. LWS-concatenation must
- // have already been done.
+ // Parses the given string as a Sec-WebSocket-Extensions header value.
+ //
+ // There must be no newline characters in the input. LWS-concatenation must
+ // have already been done before calling this method.
void Parse(const char* data, size_t size);
void Parse(const std::string& data) {
Parse(data.data(), data.size());
}
+ // Returns true if the last Parse() method call encountered any syntax error.
bool has_error() const { return has_error_; }
- const WebSocketExtension& extension() const { return extension_; }
+ // Returns the result of the last Parse() method call.
+ const std::vector<WebSocketExtension>& extensions() const {
+ return extensions_;
+ }
private:
void Consume(char c);
@@ -46,10 +49,12 @@ class NET_EXPORT_PRIVATE WebSocketExtensionParser {
static bool IsControl(char c);
static bool IsSeparator(char c);
+ // The current position in the input string.
const char* current_;
+ // The pointer of the end of the input string.
const char* end_;
bool has_error_;
- WebSocketExtension extension_;
+ std::vector<WebSocketExtension> extensions_;
DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser);
};

Powered by Google App Engine
This is Rietveld 408576698