Chromium Code Reviews| Index: net/http/http_response_headers.cc |
| =================================================================== |
| --- net/http/http_response_headers.cc (revision 140753) |
| +++ net/http/http_response_headers.cc (working copy) |
| @@ -14,10 +14,12 @@ |
| #include "base/logging.h" |
| #include "base/metrics/histogram.h" |
| #include "base/pickle.h" |
| +#include "base/stringprintf.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_piece.h" |
| #include "base/string_util.h" |
| #include "base/time.h" |
| +#include "base/values.h" |
| #include "net/base/escape.h" |
| #include "net/http/http_util.h" |
| @@ -1306,6 +1308,53 @@ |
| return true; |
| } |
| +Value* HttpResponseHeaders::NetLogCallback( |
| + NetLog::LogLevel /* log_level */) const { |
| + DictionaryValue* dict = new DictionaryValue(); |
| + ListValue* headers = new ListValue(); |
| + headers->Append(new StringValue(GetStatusLine())); |
| + void* iterator = NULL; |
| + std::string name; |
| + std::string value; |
| + while (EnumerateHeaderLines(&iterator, &name, &value)) { |
| + headers->Append( |
| + new StringValue(base::StringPrintf("%s: %s", |
| + name.c_str(), |
| + value.c_str()))); |
| + } |
| + dict->Set("headers", headers); |
| + return dict; |
| +} |
| + |
| +scoped_refptr<HttpResponseHeaders> HttpResponseHeaders::FromNetLogParam( |
| + const base::Value* event_param) { |
| + const base::DictionaryValue *dict; |
|
eroman
2012/06/06 21:27:11
bind left
mmenke
2012/06/07 19:20:46
Done.
|
| + // Not const because there's no overload of Dictionary::GetList that takes |
| + // a const list. |
| + base::ListValue *header_list; |
|
eroman
2012/06/06 21:27:11
asterisk on left
mmenke
2012/06/07 19:20:46
Done.
|
| + |
| + if (!event_param || |
| + !event_param->GetAsDictionary(&dict) || |
| + !dict->GetList("headers", &header_list)) { |
| + return scoped_refptr<HttpResponseHeaders>(NULL); |
| + } |
| + |
| + std::string raw_headers; |
| + for (base::ListValue::const_iterator it = header_list->begin(); |
| + it != header_list->end(); |
| + ++it) { |
| + std::string header_line; |
| + if (!(*it)->GetAsString(&header_line)) |
| + return scoped_refptr<HttpResponseHeaders>(NULL); |
| + |
| + raw_headers.append(header_line); |
| + raw_headers.push_back('\0'); |
| + } |
| + raw_headers.push_back('\0'); |
| + return scoped_refptr<HttpResponseHeaders>(new HttpResponseHeaders( |
| + raw_headers)); |
| +} |
| + |
| bool HttpResponseHeaders::IsChunkEncoded() const { |
| // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
| return GetHttpVersion() >= HttpVersion(1, 1) && |