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/stringprintf.h"
8 #include "base/values.h"
12 Value
* NetLogWebSocketHandshakeCallback(const std::string
* headers
,
13 NetLog::LogLevel
/* log_level */) {
14 DictionaryValue
* dict
= new DictionaryValue();
15 ListValue
* header_list
= new ListValue();
18 size_t headers_size
= headers
->size();
20 while (pos
<= headers_size
) {
21 if (pos
== headers_size
||
22 ((*headers
)[pos
] == '\r' &&
23 pos
+ 1 < headers_size
&& (*headers
)[pos
+ 1] == '\n')) {
24 std::string entry
= headers
->substr(last
, pos
- last
);
28 header_list
->Append(new StringValue(entry
));
31 // Dump WebSocket key3.
33 for (; pos
< headers_size
; ++pos
) {
34 key
+= base::StringPrintf("\\x%02x", (*headers
)[pos
] & 0xff);
36 header_list
->Append(new StringValue(key
));
44 dict
->Set("headers", header_list
);