| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_HTTP_HTTP_NET_LOG_PARAMS_H_ | 5 #ifndef NET_HTTP_HTTP_NET_LOG_PARAMS_H_ |
| 6 #define NET_HTTP_HTTP_NET_LOG_PARAMS_H_ | 6 #define NET_HTTP_HTTP_NET_LOG_PARAMS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/stringprintf.h" | |
| 14 #include "base/values.h" | |
| 15 #include "net/base/net_log.h" | 13 #include "net/base/net_log.h" |
| 16 #include "net/http/http_request_headers.h" | 14 #include "net/http/http_request_headers.h" |
| 17 #include "net/http/http_response_headers.h" | 15 |
| 16 class Value; |
| 18 | 17 |
| 19 namespace net { | 18 namespace net { |
| 20 | 19 |
| 20 class HttpResponseHeaders; |
| 21 |
| 21 class NetLogHttpRequestParameter : public NetLog::EventParameters { | 22 class NetLogHttpRequestParameter : public NetLog::EventParameters { |
| 22 public: | 23 public: |
| 23 NetLogHttpRequestParameter(const std::string& line, | 24 NetLogHttpRequestParameter(const std::string& line, |
| 24 const HttpRequestHeaders& headers) | 25 const HttpRequestHeaders& headers); |
| 25 : line_(line) { | |
| 26 headers_.CopyFrom(headers); | |
| 27 } | |
| 28 | 26 |
| 29 Value* ToValue() const { | 27 Value* ToValue() const; |
| 30 DictionaryValue* dict = new DictionaryValue(); | |
| 31 dict->SetString("line", line_); | |
| 32 ListValue* headers = new ListValue(); | |
| 33 HttpRequestHeaders::Iterator iterator(headers_); | |
| 34 while (iterator.GetNext()) { | |
| 35 headers->Append( | |
| 36 new StringValue(base::StringPrintf("%s: %s", | |
| 37 iterator.name().c_str(), | |
| 38 iterator.value().c_str()))); | |
| 39 } | |
| 40 dict->Set("headers", headers); | |
| 41 return dict; | |
| 42 } | |
| 43 | 28 |
| 44 const HttpRequestHeaders& GetHeaders() const { | 29 const HttpRequestHeaders& GetHeaders() const { |
| 45 return headers_; | 30 return headers_; |
| 46 } | 31 } |
| 47 | 32 |
| 48 private: | 33 private: |
| 49 ~NetLogHttpRequestParameter() {} | 34 virtual ~NetLogHttpRequestParameter(); |
| 50 | 35 |
| 51 const std::string line_; | 36 const std::string line_; |
| 52 HttpRequestHeaders headers_; | 37 HttpRequestHeaders headers_; |
| 53 | 38 |
| 54 DISALLOW_COPY_AND_ASSIGN(NetLogHttpRequestParameter); | 39 DISALLOW_COPY_AND_ASSIGN(NetLogHttpRequestParameter); |
| 55 }; | 40 }; |
| 56 | 41 |
| 57 class NetLogHttpResponseParameter : public NetLog::EventParameters { | 42 class NetLogHttpResponseParameter : public NetLog::EventParameters { |
| 58 public: | 43 public: |
| 59 explicit NetLogHttpResponseParameter( | 44 explicit NetLogHttpResponseParameter( |
| 60 const scoped_refptr<HttpResponseHeaders>& headers) | 45 const scoped_refptr<HttpResponseHeaders>& headers); |
| 61 : headers_(headers) {} | |
| 62 | 46 |
| 63 Value* ToValue() const { | 47 Value* ToValue() const; |
| 64 DictionaryValue* dict = new DictionaryValue(); | |
| 65 ListValue* headers = new ListValue(); | |
| 66 headers->Append(new StringValue(headers_->GetStatusLine())); | |
| 67 void* iterator = NULL; | |
| 68 std::string name; | |
| 69 std::string value; | |
| 70 while (headers_->EnumerateHeaderLines(&iterator, &name, &value)) { | |
| 71 headers->Append( | |
| 72 new StringValue(base::StringPrintf("%s: %s", name.c_str(), | |
| 73 value.c_str()))); | |
| 74 } | |
| 75 dict->Set("headers", headers); | |
| 76 return dict; | |
| 77 } | |
| 78 | 48 |
| 79 const HttpResponseHeaders& GetHeaders() const { | 49 const HttpResponseHeaders& GetHeaders() const { |
| 80 return *headers_; | 50 return *headers_; |
| 81 } | 51 } |
| 82 | 52 |
| 83 private: | 53 private: |
| 84 ~NetLogHttpResponseParameter() {} | 54 virtual ~NetLogHttpResponseParameter(); |
| 85 | 55 |
| 86 const scoped_refptr<HttpResponseHeaders> headers_; | 56 const scoped_refptr<HttpResponseHeaders> headers_; |
| 87 | 57 |
| 88 DISALLOW_COPY_AND_ASSIGN(NetLogHttpResponseParameter); | 58 DISALLOW_COPY_AND_ASSIGN(NetLogHttpResponseParameter); |
| 89 }; | 59 }; |
| 90 | 60 |
| 91 } // namespace net | 61 } // namespace net |
| 92 | 62 |
| 93 #endif // NET_HTTP_HTTP_NET_LOG_PARAMS_H_ | 63 #endif // NET_HTTP_HTTP_NET_LOG_PARAMS_H_ |
| 94 | 64 |
| OLD | NEW |