Speculative crash fix; check for a null focused view before derefing.
[chromium-blink-merge.git] / ios / net / http_protocol_logging.mm
bloba1993e13a12e6f6d8787ae05d323e1223d989fb3
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"
13 namespace {
14 const unsigned int kMaxUrlLength = 100;
17 namespace net {
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])
25       << " ...";
27   DVLOG_IF(2, ![[[request URL] scheme] isEqualToString:@"data"] ||
28               [[[request URL] absoluteString] length] <= kMaxUrlLength)
29       << "Request "
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)
55       << "Response "
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])
73       << "Text encoding: "
74       << base::SysNSStringToUTF8([response textEncodingName]);
77 }  // namespace http_protocol_logging