BBABaseAPIRequest+Private.h
7.4 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// BBABaseAPIRequest+Private.h
// BBAPods-APIRequest
//
// Created by liumuye on 2017/9/22.
// Copyright © 2017年 Baidu. All rights reserved.
//
#import "BBABaseAPIRequest.h"
#import "BBAAPIRequestOperation.h"
#import "BBAAPIRequestManagerProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@class BBAMultipartRequestPart;
/// Session含CompletionHandler的代理方法直接回调外部业务设置的Block, 与AF接口方式不同, 供NSURLProtocol接管使用
typedef void(^APIRequestWillRedirectWithHandler)(__kindof BBABaseAPIRequest *_Nonnull apiRequest, NSURLRequest * _Nonnull newURLRequest, void(^CompletionHandler)(NSURLRequest *)); // Redirect
typedef void(^APIRequestDidReceiveChallengeWithHandler)(__kindof BBABaseAPIRequest * _Nonnull apiRequest, NSURLAuthenticationChallenge *challenge, void (^CompletionHandler)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential)); // ReceiveChallenge
typedef void(^APIRequestDidReceiveResponseWithHandler)(__kindof BBABaseAPIRequest * _Nonnull apiRequest, void (^CompletionHandler)(NSURLSessionResponseDisposition disposition)); // ReceiveResponse
@interface BBAAPIRequestMetricsInfo()
// NetworkInfo
@property (atomic, assign, readwrite) NSInteger ipStack; // 0.未知 1.v4-only 2.v6-only 3.双栈
@property (atomic, assign, readwrite) NSInteger netQuality; // 1.好网 2.弱网 3.无网 4.未知
@property (atomic, assign, readwrite) BOOL isWeakNet; // 是否弱网
@property (atomic, copy, readwrite) NSString *netTypeBegin;// 请求发送前的网络制式类型
@property (atomic, copy, readwrite) NSString *netTypeEnd; // 请求结束时的网络制式类型
@property (atomic, assign, readwrite) BOOL netTypeChanged; // 请求过程中网络制式是否变化
@property (atomic, copy, readwrite) NSString *clientIP; // 出口IP
@property (atomic, assign, readwrite) BOOL viaVPN; // 是否有VPN
/// NetEngine
@property (atomic, assign, readwrite) NSUInteger netEngine; // 网络引擎类型, 1:AFN; 2.NSURLSession; 3:CroNet(TurboNet in baidu)
/// Success/Fail
@property (atomic, assign, readwrite) BOOL isSuccess; // 成功与否
@property (atomic, assign, readwrite) BOOL canceled; // 主动取消
@property (atomic, assign, readwrite) NSInteger errCode; // 错误码
@property (atomic, assign, readwrite) NSInteger underlyErrCode; // 详细错误码
@property (atomic, copy, readwrite) NSString *errMsg; // 错误简述
// TimingInfo
@property (atomic, strong, readwrite) NSDate *startTime; // 请求开始时间
@property (atomic, strong, readwrite) NSDate *resumeTime; // 请求发送时间
@property (atomic, strong, readwrite) NSDate *finishTime; // 请求结束时间
@property (atomic, assign, readwrite) NSTimeInterval queueDuration; // 排队耗时
@property (atomic, assign, readwrite) NSTimeInterval dnsDuration; // dns 耗时
@property (atomic, assign, readwrite) NSTimeInterval tcpDuration; // tcp 耗时
@property (atomic, assign, readwrite) NSTimeInterval sslDuration; // ssl 耗时
@property (atomic, assign, readwrite) NSTimeInterval ttfbDuration; // ttfb 耗时
@property (atomic, assign, readwrite) NSTimeInterval completeWaitDuration;// 回调等待耗时
/// ConnectionInfo
@property (atomic, assign, readwrite) BOOL socketReused; // 是否复用连接
@property (atomic, assign, readwrite) BOOL isIPv6Socket; // 是否是IPv6的连接
@property (atomic, assign, readwrite) BOOL viaProxy; // 是否通过代理
@property (atomic, copy, readwrite) NSString *localIPPort; // local IP和端口号 (NSURLSession iOS13+; Cronet iOS9+)
@property (atomic, copy, readwrite) NSString *remoteIPPort;// remote IP和端口号 (NSURLSession iOS13+; Cronet iOS9+)
/// HttpInfo
@property (atomic, assign, readwrite) BOOL useCache; // 命中HTTP缓存
@property (atomic, copy, readwrite) NSString *protocol; // HTTP协议类型
@property (atomic, assign, readwrite) NSInteger statusCode; // HTTP状态码
@property (atomic, assign, readwrite) NSInteger requestBodyLength; // 请求上行包大小
@property (atomic, assign, readwrite) NSInteger responseLength; // 请求响应包大小
@end
@interface BBABaseAPIRequest ()
@property (nonatomic, weak, nullable) NSURLSession *session;
@property (nonatomic, assign) BOOL useSyncOperation;
@property (nonatomic, weak) BBAAPIRequestOperation * apiRequestOperation;
@property (nonatomic, assign, readwrite) BOOL isCancelled;
@property (nonatomic, strong, nullable) NSOutputStream *downloadResumeOutputStream;
@property (nonatomic, assign) uint64_t downloadTotalSize;
@property (nonatomic, assign) uint64_t downloadWrittenSize;
@property (atomic, assign) BOOL downloadResponseHeadersBlockInvoked;
// Session直接创建Task时缓存数据
@property (nonatomic, strong) NSMutableData *mutableData;
@property (nonatomic, nullable) APIRequestWillRedirectWithHandler willRedirectHandler;
@property (nonatomic, nullable) APIRequestDidReceiveChallengeWithHandler didReceiveChallengeHandler;
@property (nonatomic, nullable) APIRequestDidReceiveResponseWithHandler didReceiveResponseHandler;
@property (atomic, assign, readwrite) NSUInteger netEngine;
@property (atomic, strong, readwrite) BBAAPIRequestMetricsInfo *metrics;
// TurboNet下强制使用SeesionConfiguration.urlCache内容
// 若命中则直接返回,TODO(liumuye): 11.13仅供搜索落地页预取使用,未达到通用目的
@property (nonatomic, assign) BOOL forceUseURLCache;
@property (nonatomic, copy) NSString *bdTraceId;
@property (nonatomic, copy, readwrite) NSString *tag;
@property (nonatomic, strong, nullable, readwrite) NSURLSessionTask *task;
@property (nonatomic, strong, readwrite) NSNumber *taskIdentfier;
//响应内容
@property (atomic, copy, nullable, readwrite) NSDictionary * responseHeaders;
@property (nonatomic, readwrite) NSInteger responseStatusCode; //状态码
@property (nonatomic, strong, nullable, readwrite) NSString *responseString;
@property (nonatomic, strong, nullable, readwrite) NSData *responseData;
@property (nonatomic, strong, nullable, readwrite) id responseJSON;
@property (nonatomic, strong, nullable, readwrite) NSURLResponse *urlResponse;
//错误信息
@property (nonatomic, strong, nullable, readwrite) NSError *error;
@property (nonatomic, assign, readwrite) NSInteger errCode;
@property (nonatomic, assign, readwrite) NSInteger underlyErrCode;
@property (nonatomic, strong, readwrite) NSDictionary *resumeDataDict;
@property (nonatomic, strong, readwrite) NSDate *startDate; // 业务调用start
@property (nonatomic, strong, readwrite) NSDate *taskResumeDate; // urlsessionTask启动
@property (nonatomic, strong, readwrite) NSDate *taskCompleteDate; // urlsessionTask完成
@property (nonatomic, strong, readwrite) NSDate *endDate; // 执行业务回调
@property (nonatomic, assign, readwrite) APIRequestQuicStatus quicStatus;
@property (nonatomic, assign) BOOL probeExecuted;
@end
@interface BBABaseAPIRequest (Private)
/// 标识网络引擎类型
- (void)markNetEngineType;
- (BOOL)isDownloadRequest;
- (uint64_t)downloadResumeTemporaryPartialSize;
- (NSError*)moveDownloadTemporaryToTarget;
- (BOOL)isUploadRequest;
- (NSMutableArray<BBAMultipartRequestPart *> *)multipartPartList;
- (void)resetAllCallbacks;
// 是否是搜索请求
- (BOOL)isSearchRequest;
// 11.6搜索使用, TODO: 11.7 门面改造后填充
- (void)resumeRequestDirectly;
@end
NS_ASSUME_NONNULL_END