Home | History | Annotate | Download | only in http
      1 // Copyright (c) 2010 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.
      4 
      5 #include "net/http/http_net_log_params.h"
      6 
      7 #include "base/stringprintf.h"
      8 #include "base/values.h"
      9 #include "net/http/http_response_headers.h"
     10 
     11 namespace net {
     12 
     13 NetLogHttpRequestParameter::NetLogHttpRequestParameter(
     14     const std::string& line,
     15     const HttpRequestHeaders& headers)
     16     : line_(line) {
     17   headers_.CopyFrom(headers);
     18 }
     19 
     20 Value* NetLogHttpRequestParameter::ToValue() const {
     21   DictionaryValue* dict = new DictionaryValue();
     22   dict->SetString("line", line_);
     23   ListValue* headers = new ListValue();
     24   HttpRequestHeaders::Iterator iterator(headers_);
     25   while (iterator.GetNext()) {
     26     headers->Append(
     27         new StringValue(base::StringPrintf("%s: %s",
     28                                            iterator.name().c_str(),
     29                                            iterator.value().c_str())));
     30   }
     31   dict->Set("headers", headers);
     32   return dict;
     33 }
     34 
     35 NetLogHttpRequestParameter::~NetLogHttpRequestParameter() {}
     36 
     37 NetLogHttpResponseParameter::NetLogHttpResponseParameter(
     38     const scoped_refptr<HttpResponseHeaders>& headers)
     39     : headers_(headers) {}
     40 
     41 Value* NetLogHttpResponseParameter::ToValue() const {
     42   DictionaryValue* dict = new DictionaryValue();
     43   ListValue* headers = new ListValue();
     44   headers->Append(new StringValue(headers_->GetStatusLine()));
     45   void* iterator = NULL;
     46   std::string name;
     47   std::string value;
     48   while (headers_->EnumerateHeaderLines(&iterator, &name, &value)) {
     49     headers->Append(
     50         new StringValue(base::StringPrintf("%s: %s", name.c_str(),
     51                                            value.c_str())));
     52   }
     53   dict->Set("headers", headers);
     54   return dict;
     55 }
     56 
     57 NetLogHttpResponseParameter::~NetLogHttpResponseParameter() {}
     58 
     59 }  // namespace net
     60