[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "net/websockets/websocket_net_log_params.h" | ||||
6 | |||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 7 | #include "base/stringprintf.h" |
8 | #include "base/values.h" | ||||
9 | |||||
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 10 | namespace net { |
11 | |||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 12 | Value* NetLogWebSocketHandshakeCallback(const std::string* headers, |
13 | NetLog::LogLevel /* log_level */) { | ||||
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 14 | DictionaryValue* dict = new DictionaryValue(); |
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 15 | ListValue* header_list = new ListValue(); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 16 | |
17 | size_t last = 0; | ||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 18 | size_t headers_size = headers->size(); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 19 | size_t pos = 0; |
20 | while (pos <= headers_size) { | ||||
21 | if (pos == headers_size || | ||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 22 | ((*headers)[pos] == '\r' && |
23 | pos + 1 < headers_size && (*headers)[pos + 1] == '\n')) { | ||||
24 | std::string entry = headers->substr(last, pos - last); | ||||
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 25 | pos += 2; |
26 | last = pos; | ||||
27 | |||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 28 | header_list->Append(new StringValue(entry)); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 29 | |
30 | if (entry.empty()) { | ||||
31 | // Dump WebSocket key3. | ||||
32 | std::string key; | ||||
33 | for (; pos < headers_size; ++pos) { | ||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 34 | key += base::StringPrintf("\\x%02x", (*headers)[pos] & 0xff); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 35 | } |
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 36 | header_list->Append(new StringValue(key)); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 37 | break; |
38 | } | ||||
39 | } else { | ||||
40 | ++pos; | ||||
41 | } | ||||
42 | } | ||||
43 | |||||
[email protected] | 4da911f | 2012-06-14 19:45:20 | [diff] [blame] | 44 | dict->Set("headers", header_list); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 45 | return dict; |
46 | } | ||||
47 | |||||
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 48 | } // namespace net |