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

Side by Side Diff: net/websockets/websocket_extension_parser.cc

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: Addressed #12 Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_extension_parser.h" 5 #include "net/websockets/websocket_extension_parser.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 8
9 namespace net { 9 namespace net {
10 10
11 WebSocketExtensionParser::WebSocketExtensionParser() {} 11 WebSocketExtensionParser::WebSocketExtensionParser() {}
12 12
13 WebSocketExtensionParser::~WebSocketExtensionParser() {} 13 WebSocketExtensionParser::~WebSocketExtensionParser() {}
14 14
15 void WebSocketExtensionParser::Parse(const char* data, size_t size) { 15 void WebSocketExtensionParser::Parse(const char* data, size_t size) {
16 current_ = data; 16 current_ = data;
17 end_ = data + size; 17 end_ = data + size;
18 has_error_ = false; 18 has_error_ = false;
19 extensions_.clear();
19 20
20 ConsumeExtension(&extension_); 21 while (true) {
21 if (has_error_) return; 22 WebSocketExtension extension;
22 ConsumeSpaces(); 23 ConsumeExtension(&extension);
23 has_error_ = has_error_ || (current_ != end_); 24 if (has_error_)
25 break;
26 extensions_.push_back(extension);
27
28 ConsumeSpaces();
29 DCHECK(!has_error_);
30
31 if (!ConsumeIfMatch(',')) {
32 break;
33 }
34 }
35
36 has_error_ = has_error_ || current_ != end_;
37 if (has_error_)
38 extensions_.clear();
24 } 39 }
25 40
26 void WebSocketExtensionParser::Consume(char c) { 41 void WebSocketExtensionParser::Consume(char c) {
27 DCHECK(!has_error_); 42 DCHECK(!has_error_);
28 ConsumeSpaces(); 43 ConsumeSpaces();
29 DCHECK(!has_error_); 44 DCHECK(!has_error_);
30 if (current_ == end_ || c != current_[0]) { 45 if (current_ == end_ || c != current_[0]) {
31 has_error_ = true; 46 has_error_ = true;
32 return; 47 return;
33 } 48 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return (0 <= c && c <= 31) || c == 127; 164 return (0 <= c && c <= 31) || c == 127;
150 } 165 }
151 166
152 // static 167 // static
153 bool WebSocketExtensionParser::IsSeparator(char c) { 168 bool WebSocketExtensionParser::IsSeparator(char c) {
154 const char separators[] = "()<>@,;:\\\"/[]?={} \t"; 169 const char separators[] = "()<>@,;:\\\"/[]?={} \t";
155 return strchr(separators, c) != NULL; 170 return strchr(separators, c) != NULL;
156 } 171 }
157 172
158 } // namespace net 173 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_extension_parser.h ('k') | net/websockets/websocket_extension_parser_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698