1 // Copyright 2012 The Chromium Authors
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/url_request/url_request_netlog_params.h"
6
7 #include <utility>
8
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
11 #include "net/base/network_isolation_key.h"
12 #include "net/cookies/site_for_cookies.h"
13 #include "net/log/net_log_capture_mode.h"
14 #include "url/gurl.h"
15 #include "url/origin.h"
16
17 namespace net {
18
NetLogURLRequestConstructorParams(const GURL & url,RequestPriority priority,NetworkTrafficAnnotationTag traffic_annotation)19 base::Value::Dict NetLogURLRequestConstructorParams(
20 const GURL& url,
21 RequestPriority priority,
22 NetworkTrafficAnnotationTag traffic_annotation) {
23 base::Value::Dict dict;
24 dict.Set("url", url.possibly_invalid_spec());
25 dict.Set("priority", RequestPriorityToString(priority));
26 dict.Set("traffic_annotation", traffic_annotation.unique_id_hash_code);
27 return dict;
28 }
29
NetLogURLRequestStartParams(const GURL & url,const std::string & method,int load_flags,const IsolationInfo & isolation_info,const SiteForCookies & site_for_cookies,const absl::optional<url::Origin> & initiator,int64_t upload_id)30 base::Value::Dict NetLogURLRequestStartParams(
31 const GURL& url,
32 const std::string& method,
33 int load_flags,
34 const IsolationInfo& isolation_info,
35 const SiteForCookies& site_for_cookies,
36 const absl::optional<url::Origin>& initiator,
37 int64_t upload_id) {
38 base::Value::Dict dict;
39 dict.Set("url", url.possibly_invalid_spec());
40 dict.Set("method", method);
41 dict.Set("load_flags", load_flags);
42 dict.Set("network_isolation_key",
43 isolation_info.network_isolation_key().ToDebugString());
44 std::string request_type;
45 switch (isolation_info.request_type()) {
46 case IsolationInfo::RequestType::kMainFrame:
47 request_type = "main frame";
48 break;
49 case IsolationInfo::RequestType::kSubFrame:
50 request_type = "subframe";
51 break;
52 case IsolationInfo::RequestType::kOther:
53 request_type = "other";
54 break;
55 }
56 dict.Set("request_type", request_type);
57 dict.Set("site_for_cookies", site_for_cookies.ToDebugString());
58 dict.Set("initiator",
59 initiator.has_value() ? initiator->Serialize() : "not an origin");
60 if (upload_id > -1)
61 dict.Set("upload_id", base::NumberToString(upload_id));
62 return dict;
63 }
64
65 } // namespace net
66