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
3 // found in the LICENSE file.
5 #include "net/websockets/websocket_net_log_params.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/values.h"
12 base::Value
* NetLogWebSocketHandshakeCallback(
13 const std::string
* headers
,
14 NetLog::LogLevel
/* log_level */) {
15 base::DictionaryValue
* dict
= new base::DictionaryValue();
16 base::ListValue
* header_list
= new base::ListValue();
19 size_t headers_size
= headers
->size();
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
);
29 header_list
->Append(new base::StringValue(entry
));
32 // Dump WebSocket key3.
34 for (; pos
< headers_size
; ++pos
) {
35 key
+= base::StringPrintf("\\x%02x", (*headers
)[pos
] & 0xff);
37 header_list
->Append(new base::StringValue(key
));
45 dict
->Set("headers", header_list
);