| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_WEBSOCKETS_WEBSOCKET_NET_LOG_PARAMS_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_NET_LOG_PARAMS_H_ |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_NET_LOG_PARAMS_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_NET_LOG_PARAMS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 class NetLogWebSocketHandshakeParameter : public NetLog::EventParameters { | 22 class NetLogWebSocketHandshakeParameter : public NetLog::EventParameters { |
| 23 public: | 23 public: |
| 24 explicit NetLogWebSocketHandshakeParameter(const std::string& headers) | 24 explicit NetLogWebSocketHandshakeParameter(const std::string& headers); |
| 25 : headers_(headers) { | |
| 26 } | |
| 27 | 25 |
| 28 Value* ToValue() const { | 26 virtual Value* ToValue() const; |
| 29 DictionaryValue* dict = new DictionaryValue(); | |
| 30 ListValue* headers = new ListValue(); | |
| 31 | |
| 32 size_t last = 0; | |
| 33 size_t headers_size = headers_.size(); | |
| 34 size_t pos = 0; | |
| 35 while (pos <= headers_size) { | |
| 36 if (pos == headers_size || | |
| 37 (headers_[pos] == '\r' && | |
| 38 pos + 1 < headers_size && headers_[pos + 1] == '\n')) { | |
| 39 std::string entry = headers_.substr(last, pos - last); | |
| 40 pos += 2; | |
| 41 last = pos; | |
| 42 | |
| 43 headers->Append(new StringValue(entry)); | |
| 44 | |
| 45 if (entry.empty()) { | |
| 46 // Dump WebSocket key3. | |
| 47 std::string key; | |
| 48 for (; pos < headers_size; ++pos) { | |
| 49 key += base::StringPrintf("\\x%02x", headers_[pos] & 0xff); | |
| 50 } | |
| 51 headers->Append(new StringValue(key)); | |
| 52 break; | |
| 53 } | |
| 54 } else { | |
| 55 ++pos; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 dict->Set("headers", headers); | |
| 60 return dict; | |
| 61 } | |
| 62 | 27 |
| 63 private: | 28 private: |
| 64 ~NetLogWebSocketHandshakeParameter() {} | 29 virtual ~NetLogWebSocketHandshakeParameter(); |
| 65 | 30 |
| 66 const std::string headers_; | 31 const std::string headers_; |
| 67 | 32 |
| 68 DISALLOW_COPY_AND_ASSIGN(NetLogWebSocketHandshakeParameter); | 33 DISALLOW_COPY_AND_ASSIGN(NetLogWebSocketHandshakeParameter); |
| 69 }; | 34 }; |
| 70 | 35 |
| 71 } // namespace net | 36 } // namespace net |
| 72 | 37 |
| 73 #endif // NET_WEBSOCKETS_WEBSOCKET_NET_LOG_PARAMS_H_ | 38 #endif // NET_WEBSOCKETS_WEBSOCKET_NET_LOG_PARAMS_H_ |
| OLD | NEW |