summaryrefslogtreecommitdiffstats
path: root/ios/net/http_protocol_logging.mm
blob: a1993e13a12e6f6d8787ae05d323e1223d989fb3 (plain)
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
// 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"

#include <Foundation/Foundation.h>

#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/net/url_scheme_util.h"

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