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