|
| 1 | +// |
| 2 | +// IBGNetworkLogger.h |
| 3 | +// InstabugCore |
| 4 | +// |
| 5 | +// Created by Yousef Hamza on 5/17/18. |
| 6 | +// Copyright © 2018 Instabug. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import <Foundation/Foundation.h> |
| 10 | +#import "IBGTypes.h" |
| 11 | + |
| 12 | +@interface IBGNetworkLogger : NSObject |
| 13 | + |
| 14 | +@property (class, atomic, assign) BOOL enabled; |
| 15 | + |
| 16 | +/* CHECK NULLABILITY! */ |
| 17 | +typedef void (^NetworkObfuscationCompletionBlock)(NSData * _Nullable data, NSURLResponse * _Nonnull response); |
| 18 | + |
| 19 | + |
| 20 | +/** |
| 21 | + @brief Enable logging for network requests and responses on a custom NSURLSessionConfiguration. |
| 22 | + |
| 23 | + @discussion Logging for network requests and responses may not work if you're using a custom `NSURLSession` object. |
| 24 | + If this is the case, call this method passing in your custom NSURLSessions's configuration to enable logging for it. |
| 25 | + |
| 26 | + @param URLSessionConfiguration The NSURLSessionConfiguration of your custom NSURLSession. |
| 27 | + */ |
| 28 | ++ (void)enableLoggingForURLSessionConfiguration:(NSURLSessionConfiguration *_Nonnull)URLSessionConfiguration; |
| 29 | + |
| 30 | + |
| 31 | +/** |
| 32 | + @brief Use to obfuscate a request that's going to be included in network logs. |
| 33 | + |
| 34 | + @discussion Use this method if you want to make any modifications to requests before it is added to the network log. |
| 35 | + This won't be applied to already filtered requests |
| 36 | + |
| 37 | + Note that thsese changes doesn't affect the actual request. |
| 38 | + |
| 39 | + The provided block will be called for every request. You should do whatever processing you need to do on the request inside |
| 40 | + that block, then return a request to be included in network logs. |
| 41 | + |
| 42 | + This method usage overrides modifications made by `setNetworkLoggingURLObfuscationHandler:`. |
| 43 | + |
| 44 | + @param obfuscationHandler A block that takes a request and returns a new modified one to be logged.. |
| 45 | + */ |
| 46 | ++ (void)setRequestObfuscationHandler:(nonnull NSURLRequest * _Nonnull (^)(NSURLRequest * _Nonnull request))obfuscationHandler; |
| 47 | + |
| 48 | +/** |
| 49 | + @brief Use to obfuscate a request's response that's going to be included in network logs. |
| 50 | + |
| 51 | + @discussion Use this method if you want to make any modifications to a request's respone and its data before it's |
| 52 | + added to network logs. |
| 53 | + |
| 54 | + The provided block will be called for every response. You should do whatever processing you need to do on the response |
| 55 | + and data inside that block, then return response and data to be included in network logs. Changes you make to the |
| 56 | + response and its data only affect network logs, not the actual response. |
| 57 | + |
| 58 | + @param obfuscationHandler A block that takes the original response, its data and a return block as parameters. The |
| 59 | + return block should be called with the modified data and response. |
| 60 | + */ |
| 61 | ++ (void)setResponseObfuscationHandler:(void (^_Nonnull)(NSData * _Nullable responseData, NSURLResponse * _Nonnull response, NetworkObfuscationCompletionBlock _Nonnull returnBlock))obfuscationHandler; |
| 62 | + |
| 63 | +/** |
| 64 | + @brief Use to get callbacks about progress of sending body content of a particular request when networking logging is |
| 65 | + enabled. |
| 66 | + |
| 67 | + @discussion The provided block will get periodical callbacks about the progress of sending the body content of a request. |
| 68 | + |
| 69 | + @param URL URL which will be attached with requestProgressHandler. |
| 70 | + @param requestProgressHandler A block that will be called for the requestURL when SDK intercept that request. |
| 71 | + |
| 72 | + */ |
| 73 | ++ (void)setProgressHandlerForRequestURL:(nonnull NSURL *)URL |
| 74 | + progressHandler:(nonnull void (^)(NSURLSessionTask * _Nonnull task, int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend))requestProgressHandler; |
| 75 | + |
| 76 | + |
| 77 | +/** |
| 78 | + @brief Used to ask whether your app is prepared to handle a particular authentication challenge. Can be called on any thread. |
| 79 | + |
| 80 | + @discussion Set this block if your app implements SSL pinning and you have network logging enabled. |
| 81 | + |
| 82 | + @param protectionSpaceHandler A block that takes the protection space for the authentication challenge and should return |
| 83 | + true or false. |
| 84 | + */ |
| 85 | ++ (void)setCanAuthenticateAgainstProtectionSpaceHandler:(BOOL(^_Nonnull)(NSURLProtectionSpace * _Nonnull protectionSpace))protectionSpaceHandler; |
| 86 | + |
| 87 | + |
| 88 | +/** |
| 89 | + @brief Used to process an authentication challenge and return an NSURLCredential object. |
| 90 | + |
| 91 | + @discussion Set this block if your app implements SSL pinning and you have network logging enabled. |
| 92 | + |
| 93 | + @param reciveChallengeHandler A block that takes the authentication challenge and returns NSURLCredential. |
| 94 | + */ |
| 95 | ++ (void)setDidReceiveAuthenticationChallengeHandler:(NSURLCredential* _Nonnull (^_Nonnull)(NSURLAuthenticationChallenge * _Nonnull challenge))reciveChallengeHandler; |
| 96 | + |
| 97 | +@end |
0 commit comments