Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: net/http/http_response_headers.cc

Issue 10399083: Make NetLog take in callbacks that return Values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // The rules for header parsing were borrowed from Firefox: 5 // The rules for header parsing were borrowed from Firefox:
6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp
7 // The rules for parsing content-types were also borrowed from Firefox: 7 // The rules for parsing content-types were also borrowed from Firefox:
8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
9 9
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
11 11
12 #include <algorithm> 12 #include <algorithm>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/pickle.h" 16 #include "base/pickle.h"
17 #include "base/stringprintf.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
18 #include "base/string_piece.h" 19 #include "base/string_piece.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "base/time.h" 21 #include "base/time.h"
22 #include "base/values.h"
21 #include "net/base/escape.h" 23 #include "net/base/escape.h"
22 #include "net/http/http_util.h" 24 #include "net/http/http_util.h"
23 25
24 using base::StringPiece; 26 using base::StringPiece;
25 using base::Time; 27 using base::Time;
26 using base::TimeDelta; 28 using base::TimeDelta;
27 29
28 namespace net { 30 namespace net {
29 31
30 //----------------------------------------------------------------------------- 32 //-----------------------------------------------------------------------------
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 1301
1300 // We have all the values; let's verify that they make sense for a 206 1302 // We have all the values; let's verify that they make sense for a 206
1301 // response. 1303 // response.
1302 if (*first_byte_position < 0 || *last_byte_position < 0 || 1304 if (*first_byte_position < 0 || *last_byte_position < 0 ||
1303 *instance_length < 0 || *instance_length - 1 < *last_byte_position) 1305 *instance_length < 0 || *instance_length - 1 < *last_byte_position)
1304 return false; 1306 return false;
1305 1307
1306 return true; 1308 return true;
1307 } 1309 }
1308 1310
1311 Value* HttpResponseHeaders::NetLogCallback(
1312 NetLog::LogLevel /* log_level */) const {
1313 DictionaryValue* dict = new DictionaryValue();
1314 ListValue* headers = new ListValue();
1315 headers->Append(new StringValue(GetStatusLine()));
1316 void* iterator = NULL;
1317 std::string name;
1318 std::string value;
1319 while (EnumerateHeaderLines(&iterator, &name, &value)) {
1320 headers->Append(
1321 new StringValue(base::StringPrintf("%s: %s",
1322 name.c_str(),
1323 value.c_str())));
1324 }
1325 dict->Set("headers", headers);
1326 return dict;
1327 }
1328
1329 scoped_refptr<HttpResponseHeaders> HttpResponseHeaders::FromNetLogParam(
1330 const base::Value* event_param) {
1331 const base::DictionaryValue *dict;
eroman 2012/06/06 21:27:11 bind left
mmenke 2012/06/07 19:20:46 Done.
1332 // Not const because there's no overload of Dictionary::GetList that takes
1333 // a const list.
1334 base::ListValue *header_list;
eroman 2012/06/06 21:27:11 asterisk on left
mmenke 2012/06/07 19:20:46 Done.
1335
1336 if (!event_param ||
1337 !event_param->GetAsDictionary(&dict) ||
1338 !dict->GetList("headers", &header_list)) {
1339 return scoped_refptr<HttpResponseHeaders>(NULL);
1340 }
1341
1342 std::string raw_headers;
1343 for (base::ListValue::const_iterator it = header_list->begin();
1344 it != header_list->end();
1345 ++it) {
1346 std::string header_line;
1347 if (!(*it)->GetAsString(&header_line))
1348 return scoped_refptr<HttpResponseHeaders>(NULL);
1349
1350 raw_headers.append(header_line);
1351 raw_headers.push_back('\0');
1352 }
1353 raw_headers.push_back('\0');
1354 return scoped_refptr<HttpResponseHeaders>(new HttpResponseHeaders(
1355 raw_headers));
1356 }
1357
1309 bool HttpResponseHeaders::IsChunkEncoded() const { 1358 bool HttpResponseHeaders::IsChunkEncoded() const {
1310 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1359 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1311 return GetHttpVersion() >= HttpVersion(1, 1) && 1360 return GetHttpVersion() >= HttpVersion(1, 1) &&
1312 HasHeaderValue("Transfer-Encoding", "chunked"); 1361 HasHeaderValue("Transfer-Encoding", "chunked");
1313 } 1362 }
1314 1363
1315 } // namespace net 1364 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698