OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 | 6 |
7 #include "cronet_c_for_grpc.h" | 7 #include "cronet_c_for_grpc.h" |
8 | 8 |
| 9 // A block, that takes a request, and returns YES if the request should |
| 10 // be handled. |
| 11 typedef BOOL (^RequestFilterBlock)(NSURLRequest* request); |
| 12 |
9 // Interface for installing Cronet. | 13 // Interface for installing Cronet. |
10 CRONET_EXPORT | 14 CRONET_EXPORT |
11 @interface Cronet : NSObject | 15 @interface Cronet : NSObject |
12 | 16 |
13 // Sets whether HTTP/2 should be supported by CronetEngine. This method only has | 17 // Sets whether HTTP/2 should be supported by CronetEngine. This method only has |
14 // any effect before |start| is called. | 18 // any effect before |start| is called. |
15 + (void)setHttp2Enabled:(BOOL)http2Enabled; | 19 + (void)setHttp2Enabled:(BOOL)http2Enabled; |
16 | 20 |
17 // Sets whether QUIC should be supported by CronetEngine. This method only has | 21 // Sets whether QUIC should be supported by CronetEngine. This method only has |
18 // any effect before |start| is called. | 22 // any effect before |start| is called. |
19 + (void)setQuicEnabled:(BOOL)quicEnabled; | 23 + (void)setQuicEnabled:(BOOL)quicEnabled; |
20 | 24 |
21 // Adds hint that host supports QUIC on altPort. This method only has any effect | 25 // Adds hint that host supports QUIC on altPort. This method only has any effect |
22 // before |start| is called. | 26 // before |start| is called. |
23 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort; | 27 + (void)addQuicHint:(NSString*)host port:(int)port altPort:(int)altPort; |
24 | 28 |
25 // |userAgent| is expected to be of the form Product/Version. | 29 // Sets the User-Agent request header string to be sent with all requests. |
26 // Example: Foo/3.0.0.0 | 30 // If |partial| is set to YES, then actual user agent value is based on device |
| 31 // model, OS version, and |userAgent| argument. For example "Foo/3.0.0.0" is |
| 32 // sent as "Mozilla/5.0 (iPhone; CPU iPhone OS 9_3 like Mac OS X) |
| 33 // AppleWebKit/601.1 (KHTML, like Gecko) Foo/3.0.0.0 Mobile/15G31 |
| 34 // Safari/601.1.46". |
| 35 // If |partial| is set to NO, then |userAgent| value is complete value sent to |
| 36 // the remote. For Example: "Foo/3.0.0.0" is sent as "Foo/3.0.0.0". |
27 // | 37 // |
28 // This method only has any effect before |start| is called. | 38 // This method only has any effect before |start| is called. |
29 + (void)setPartialUserAgent:(NSString*)userAgent; | 39 + (void)setUserAgent:(NSString*)userAgent partial:(BOOL)partial; |
30 | 40 |
31 // Sets SSLKEYLogFileName to export SSL key for Wireshark decryption of packet | 41 // Sets SSLKEYLogFileName to export SSL key for Wireshark decryption of packet |
32 // captures. This method only has any effect before |start| is called. | 42 // captures. This method only has any effect before |start| is called. |
33 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName; | 43 + (void)setSslKeyLogFileName:(NSString*)sslKeyLogFileName; |
34 | 44 |
| 45 // Sets the block used to determine whether or not Cronet should handle the |
| 46 // request. If the block is not set, Cronet will handle all requests. Cronet |
| 47 // retains strong reference to the block, which can be released by calling this |
| 48 // method with nil block. |
| 49 + (void)setRequestFilterBlock:(RequestFilterBlock)block; |
| 50 |
35 // Starts CronetEngine. It is recommended to call this method on the application | 51 // Starts CronetEngine. It is recommended to call this method on the application |
36 // main thread. If the method is called on any thread other than the main one, | 52 // main thread. If the method is called on any thread other than the main one, |
37 // the method will internally try to execute synchronously using the main GCD | 53 // the method will internally try to execute synchronously using the main GCD |
38 // queue. Please make sure that the main thread is not blocked by a job | 54 // queue. Please make sure that the main thread is not blocked by a job |
39 // that calls this method; otherwise, a deadlock can occur. | 55 // that calls this method; otherwise, a deadlock can occur. |
40 + (void)start; | 56 + (void)start; |
41 | 57 |
| 58 // Registers Cronet as HttpProtocol Handler. Once registered, Cronet intercepts |
| 59 // and handles all requests made through NSURLConnection and shared |
| 60 // NSURLSession. |
| 61 // This method must be called after |start|. |
| 62 + (void)registerHttpProtocolHandler; |
| 63 |
| 64 // Unregister Cronet as HttpProtocol Handler. This means that Cronet will stop |
| 65 // intercepting requests, however, it won't tear down the Cronet environment. |
| 66 // This method must be called after |start|. |
| 67 + (void)unregisterHttpProtocolHandler; |
| 68 |
| 69 // Installs Cronet into NSURLSessionConfiguration so that all |
| 70 // NSURLSessions created with this configuration will use the Cronet stack. |
| 71 // Note that all Cronet settings are global and are shared between |
| 72 // all NSURLSessions & NSURLConnections that use the Cronet stack. |
| 73 // This method must be called after |start|. |
| 74 + (void)installIntoSessionConfiguration:(NSURLSessionConfiguration*)config; |
| 75 |
42 // Starts net-internals logging to a file named |fileName| in the application | 76 // Starts net-internals logging to a file named |fileName| in the application |
43 // temporary directory. |fileName| must not be empty. Log level is determined | 77 // temporary directory. |fileName| must not be empty. Log level is determined |
44 // by |logBytes| - if YES then LOG_ALL otherwise LOG_ALL_BUT_BYTES. If the file | 78 // by |logBytes| - if YES then LOG_ALL otherwise LOG_ALL_BUT_BYTES. If the file |
45 // exists it is truncated before starting. If actively logging the call is | 79 // exists it is truncated before starting. If actively logging the call is |
46 // ignored. | 80 // ignored. |
47 + (void)startNetLogToFile:(NSString*)fileName logBytes:(BOOL)logBytes; | 81 + (void)startNetLogToFile:(NSString*)fileName logBytes:(BOOL)logBytes; |
48 | 82 |
49 // Stop net-internals logging and flush file to disk. If a logging session is | 83 // Stop net-internals logging and flush file to disk. If a logging session is |
50 // not in progress this call is ignored. | 84 // not in progress this call is ignored. |
51 + (void)stopNetLog; | 85 + (void)stopNetLog; |
52 | 86 |
53 // Returns the full user-agent that the stack uses. | 87 // Returns the full user-agent that the stack uses. |
54 // This is the exact string servers will see. | 88 // This is the exact string servers will see. |
55 + (NSString*)getUserAgent; | 89 + (NSString*)getUserAgent; |
56 | 90 |
57 // Get a pointer to global instance of cronet_engine for GRPC C API. | 91 // Get a pointer to global instance of cronet_engine for GRPC C API. |
58 + (cronet_engine*)getGlobalEngine; | 92 + (cronet_engine*)getGlobalEngine; |
59 | 93 |
| 94 // Returns differences in metrics collected by Cronet since the last call to |
| 95 // getGlobalMetricsDeltas, serialized as a [protobuf] |
| 96 // (https://developers.google.com/protocol-buffers). |
| 97 // |
| 98 // Cronet starts collecting these metrics after the first call to |
| 99 // getGlobalMetricsDeltras, so the first call returns no |
| 100 // useful data as no metrics have yet been collected. |
| 101 + (NSData*)getGlobalMetricsDeltas; |
| 102 |
| 103 // Sets Host Resolver Rules for testing. |
| 104 // This method only has any effect before |start| is called. |
| 105 + (void)setHostResolverRulesForTesting:(NSString*)hostResolverRulesForTesting; |
| 106 |
| 107 // Enables TestCertVerifier which accepts all certificates for testing. |
| 108 // This method only has any effect before |start| is called. |
| 109 + (void)enableTestCertVerifierForTesting; |
| 110 |
60 @end | 111 @end |
OLD | NEW |