1 // Copyright 2012 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.
5 #include "ios/net/http_protocol_logging.h"
7 #include <Foundation/Foundation.h>
9 #include "base/logging.h"
10 #include "base/strings/sys_string_conversions.h"
11 #import "ios/net/url_scheme_util.h"
14 const unsigned int kMaxUrlLength = 100;
19 void LogNSURLRequest(NSURLRequest* request) {
20 DVLOG_IF(2, UrlHasDataScheme([request URL]) &&
21 [[[request URL] absoluteString] length] > kMaxUrlLength)
22 << "Request (data scheme) "
23 << base::SysNSStringToUTF8(
24 [[[request URL] absoluteString] substringToIndex:kMaxUrlLength])
27 DVLOG_IF(2, ![[[request URL] scheme] isEqualToString:@"data"] ||
28 [[[request URL] absoluteString] length] <= kMaxUrlLength)
30 << base::SysNSStringToUTF8([[request URL] description]);
32 DVLOG_IF(2, ![[request HTTPMethod] isEqualToString:@"GET"])
33 << base::SysNSStringToUTF8([request HTTPMethod]);
35 DVLOG_IF(2, [request allHTTPHeaderFields])
36 << base::SysNSStringToUTF8([[request allHTTPHeaderFields] description]);
38 DVLOG_IF(2, [request networkServiceType])
39 << "Service type: " << [request networkServiceType];
41 DVLOG_IF(2, ![request HTTPShouldHandleCookies]) << "No cookies";
43 DVLOG_IF(2, [request HTTPShouldUsePipelining]) << "Pipelining allowed";
46 void LogNSURLResponse(NSURLResponse* response) {
47 DVLOG_IF(2, UrlHasDataScheme([response URL]) &&
48 [[[response URL] absoluteString] length] > kMaxUrlLength)
49 << "Response (data scheme) "
50 << base::SysNSStringToUTF8(
51 [[[response URL] absoluteString] substringToIndex:kMaxUrlLength]);
53 DVLOG_IF(2, !UrlHasDataScheme([response URL]) ||
54 [[[response URL] absoluteString] length] <= kMaxUrlLength)
56 << base::SysNSStringToUTF8([[response URL] description]);
58 DVLOG_IF(2, [response isKindOfClass:[NSHTTPURLResponse class]] &&
59 [(NSHTTPURLResponse*)response allHeaderFields])
60 << base::SysNSStringToUTF8(
61 [[(NSHTTPURLResponse*)response allHeaderFields] description]);
63 DVLOG_IF(2, [response expectedContentLength])
64 << "Length: " << [response expectedContentLength];
66 DVLOG_IF(2, [response MIMEType])
67 << "MIMEType: " << base::SysNSStringToUTF8([response MIMEType]);
69 DVLOG_IF(2, [response isKindOfClass:[NSHTTPURLResponse class]])
70 << "Response code: " << [(NSHTTPURLResponse*)response statusCode];
72 DVLOG_IF(2, [response textEncodingName])
74 << base::SysNSStringToUTF8([response textEncodingName]);
77 } // namespace http_protocol_logging