blob: 7c1a2925b208f243de7f3afe7a6ebc3df14dc2d3 [file] [log] [blame]
[email protected]4da911f2012-06-14 19:45:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]78994ab02010-12-08 18:06:442// 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
[email protected]4da911f2012-06-14 19:45:207#include "base/stringprintf.h"
8#include "base/values.h"
9
[email protected]78994ab02010-12-08 18:06:4410namespace net {
11
[email protected]4da911f2012-06-14 19:45:2012Value* NetLogWebSocketHandshakeCallback(const std::string* headers,
13 NetLog::LogLevel /* log_level */) {
[email protected]78994ab02010-12-08 18:06:4414 DictionaryValue* dict = new DictionaryValue();
[email protected]4da911f2012-06-14 19:45:2015 ListValue* header_list = new ListValue();
[email protected]78994ab02010-12-08 18:06:4416
17 size_t last = 0;
[email protected]4da911f2012-06-14 19:45:2018 size_t headers_size = headers->size();
[email protected]78994ab02010-12-08 18:06:4419 size_t pos = 0;
20 while (pos <= headers_size) {
21 if (pos == headers_size ||
[email protected]4da911f2012-06-14 19:45:2022 ((*headers)[pos] == '\r' &&
23 pos + 1 < headers_size && (*headers)[pos + 1] == '\n')) {
24 std::string entry = headers->substr(last, pos - last);
[email protected]78994ab02010-12-08 18:06:4425 pos += 2;
26 last = pos;
27
[email protected]4da911f2012-06-14 19:45:2028 header_list->Append(new StringValue(entry));
[email protected]78994ab02010-12-08 18:06:4429
30 if (entry.empty()) {
31 // Dump WebSocket key3.
32 std::string key;
33 for (; pos < headers_size; ++pos) {
[email protected]4da911f2012-06-14 19:45:2034 key += base::StringPrintf("\\x%02x", (*headers)[pos] & 0xff);
[email protected]78994ab02010-12-08 18:06:4435 }
[email protected]4da911f2012-06-14 19:45:2036 header_list->Append(new StringValue(key));
[email protected]78994ab02010-12-08 18:06:4437 break;
38 }
39 } else {
40 ++pos;
41 }
42 }
43
[email protected]4da911f2012-06-14 19:45:2044 dict->Set("headers", header_list);
[email protected]78994ab02010-12-08 18:06:4445 return dict;
46}
47
[email protected]78994ab02010-12-08 18:06:4448} // namespace net