forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttp_protocol_logging.mm
81 lines (60 loc) · 2.81 KB
/
http_protocol_logging.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/net/http_protocol_logging.h"
#import <Foundation/Foundation.h>
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/net/url_scheme_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const unsigned int kMaxUrlLength = 100;
}
namespace net {
void LogNSURLRequest(NSURLRequest* request) {
DVLOG_IF(2, UrlHasDataScheme([request URL]) &&
[[[request URL] absoluteString] length] > kMaxUrlLength)
<< "Request (data scheme) "
<< base::SysNSStringToUTF8(
[[[request URL] absoluteString] substringToIndex:kMaxUrlLength])
<< " ...";
DVLOG_IF(2, ![[[request URL] scheme] isEqualToString:@"data"] ||
[[[request URL] absoluteString] length] <= kMaxUrlLength)
<< "Request "
<< base::SysNSStringToUTF8([[request URL] description]);
DVLOG_IF(2, ![[request HTTPMethod] isEqualToString:@"GET"])
<< base::SysNSStringToUTF8([request HTTPMethod]);
DVLOG_IF(2, [request allHTTPHeaderFields])
<< base::SysNSStringToUTF8([[request allHTTPHeaderFields] description]);
DVLOG_IF(2, [request networkServiceType])
<< "Service type: " << [request networkServiceType];
DVLOG_IF(2, ![request HTTPShouldHandleCookies]) << "No cookies";
DVLOG_IF(2, [request HTTPShouldUsePipelining]) << "Pipelining allowed";
}
void LogNSURLResponse(NSURLResponse* response) {
DVLOG_IF(2, UrlHasDataScheme([response URL]) &&
[[[response URL] absoluteString] length] > kMaxUrlLength)
<< "Response (data scheme) "
<< base::SysNSStringToUTF8(
[[[response URL] absoluteString] substringToIndex:kMaxUrlLength]);
DVLOG_IF(2, !UrlHasDataScheme([response URL]) ||
[[[response URL] absoluteString] length] <= kMaxUrlLength)
<< "Response "
<< base::SysNSStringToUTF8([[response URL] description]);
DVLOG_IF(2, [response isKindOfClass:[NSHTTPURLResponse class]] &&
[(NSHTTPURLResponse*)response allHeaderFields])
<< base::SysNSStringToUTF8(
[[(NSHTTPURLResponse*)response allHeaderFields] description]);
DVLOG_IF(2, [response expectedContentLength])
<< "Length: " << [response expectedContentLength];
DVLOG_IF(2, [response MIMEType])
<< "MIMEType: " << base::SysNSStringToUTF8([response MIMEType]);
DVLOG_IF(2, [response isKindOfClass:[NSHTTPURLResponse class]])
<< "Response code: " << [(NSHTTPURLResponse*)response statusCode];
DVLOG_IF(2, [response textEncodingName])
<< "Text encoding: "
<< base::SysNSStringToUTF8([response textEncodingName]);
}
} // namespace http_protocol_logging