| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_net_log_params.h" | 5 #include "net/websockets/websocket_net_log_params.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 Value* NetLogWebSocketHandshakeCallback(const std::string* headers, | 12 base::Value* NetLogWebSocketHandshakeCallback( |
| 13 NetLog::LogLevel /* log_level */) { | 13 const std::string* headers, |
| 14 DictionaryValue* dict = new DictionaryValue(); | 14 NetLog::LogLevel /* log_level */) { |
| 15 ListValue* header_list = new ListValue(); | 15 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 16 base::ListValue* header_list = new base::ListValue(); |
| 16 | 17 |
| 17 size_t last = 0; | 18 size_t last = 0; |
| 18 size_t headers_size = headers->size(); | 19 size_t headers_size = headers->size(); |
| 19 size_t pos = 0; | 20 size_t pos = 0; |
| 20 while (pos <= headers_size) { | 21 while (pos <= headers_size) { |
| 21 if (pos == headers_size || | 22 if (pos == headers_size || |
| 22 ((*headers)[pos] == '\r' && | 23 ((*headers)[pos] == '\r' && |
| 23 pos + 1 < headers_size && (*headers)[pos + 1] == '\n')) { | 24 pos + 1 < headers_size && (*headers)[pos + 1] == '\n')) { |
| 24 std::string entry = headers->substr(last, pos - last); | 25 std::string entry = headers->substr(last, pos - last); |
| 25 pos += 2; | 26 pos += 2; |
| 26 last = pos; | 27 last = pos; |
| 27 | 28 |
| 28 header_list->Append(new StringValue(entry)); | 29 header_list->Append(new base::StringValue(entry)); |
| 29 | 30 |
| 30 if (entry.empty()) { | 31 if (entry.empty()) { |
| 31 // Dump WebSocket key3. | 32 // Dump WebSocket key3. |
| 32 std::string key; | 33 std::string key; |
| 33 for (; pos < headers_size; ++pos) { | 34 for (; pos < headers_size; ++pos) { |
| 34 key += base::StringPrintf("\\x%02x", (*headers)[pos] & 0xff); | 35 key += base::StringPrintf("\\x%02x", (*headers)[pos] & 0xff); |
| 35 } | 36 } |
| 36 header_list->Append(new StringValue(key)); | 37 header_list->Append(new base::StringValue(key)); |
| 37 break; | 38 break; |
| 38 } | 39 } |
| 39 } else { | 40 } else { |
| 40 ++pos; | 41 ++pos; |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 dict->Set("headers", header_list); | 45 dict->Set("headers", header_list); |
| 45 return dict; | 46 return dict; |
| 46 } | 47 } |
| 47 | 48 |
| 48 } // namespace net | 49 } // namespace net |
| OLD | NEW |