Skip to content

Commit 1473c5e

Browse files
committed
Merge pull request #23 from longbai/upload-cdn-log
Upload cdn log
2 parents e216686 + df26cc1 commit 1473c5e

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

QiniuSDK/Http/QNHttpManager.m

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@ @interface QNHttpManager ()
1818
@property (nonatomic) AFHTTPRequestOperationManager *httpManager;
1919
@end
2020

21-
static NSString *userAgent = nil;
22-
2321
@implementation QNHttpManager
2422

25-
+ (void)initialize {
26-
userAgent = QNUserAgent();
27-
}
28-
2923
- (instancetype)init {
3024
if (self = [super init]) {
3125
_httpManager = [[AFHTTPRequestOperationManager alloc] init];
@@ -41,14 +35,17 @@ + (QNResponseInfo *)buildResponseInfo:(AFHTTPRequestOperation *)operation
4135
withResponse:(id)responseObject {
4236
QNResponseInfo *info;
4337
NSString *host = operation.request.URL.host;
44-
// NSArray *hostIp = [QNDns getAddresses:host];
4538

4639
if (operation.response) {
4740
NSDictionary *headers = [operation.response allHeaderFields];
4841
NSString *reqId = headers[@"X-Reqid"];
4942
NSString *xlog = headers[@"X-Log"];
43+
NSString *xvia = headers[@"X-Via"];
44+
if (xvia == nil) {
45+
xvia = headers[@"X-Px"];
46+
}
5047
int status = (int)[operation.response statusCode];
51-
info = [[QNResponseInfo alloc] init:status withReqId:reqId withXLog:xlog withHost:host withDuration:duration withBody:responseObject];
48+
info = [[QNResponseInfo alloc] init:status withReqId:reqId withXLog:xlog withXVia:xvia withHost:host withDuration:duration withBody:responseObject];
5249
}
5350
else {
5451
info = [QNResponseInfo responseInfoWithNetError:error host:host duration:duration];
@@ -69,10 +66,12 @@ - (void) sendRequest:(NSMutableURLRequest *)request
6966
if (info.isOK) {
7067
resp = responseObject;
7168
}
69+
NSLog(@"success %@", info);
7270
completeBlock(info, resp);
7371
} failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
7472
double duration = [[NSDate date] timeIntervalSinceDate:startTime];
7573
QNResponseInfo *info = [QNHttpManager buildResponseInfo:operation withError:error withDuration:duration withResponse:operation.responseData];
74+
NSLog(@"failure %@", info);
7675
completeBlock(info, nil);
7776
}
7877

@@ -85,7 +84,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
8584
}
8685
[request setTimeoutInterval:kQNTimeoutInterval];
8786

88-
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
87+
[request setValue:QNUserAgent() forHTTPHeaderField:@"User-Agent"];
8988
[request setValue:nil forHTTPHeaderField:@"Accept-Language"];
9089
[_httpManager.operationQueue addOperation:operation];
9190
}

QiniuSDK/Http/QNResponseInfo.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ extern const int kQNFileError;
4848
*/
4949
@property (nonatomic, copy, readonly) NSString *xlog;
5050

51+
/**
52+
* cdn服务器内部跟踪记录
53+
*/
54+
@property (nonatomic, copy, readonly) NSString *xvia;
55+
5156
/**
5257
* 错误信息,出错时请反馈此记录
5358
*/
@@ -69,9 +74,9 @@ extern const int kQNFileError;
6974
@property (nonatomic, readonly) NSString *serverIp;
7075

7176
/**
72-
* 服务器IP
77+
* 网络类型
7378
*/
74-
@property (nonatomic, readonly) NSString *networkType;
79+
//@property (nonatomic, readonly) NSString *networkType;
7580

7681
/**
7782
* 是否取消
@@ -152,6 +157,7 @@ extern const int kQNFileError;
152157
- (instancetype)init:(int)status
153158
withReqId:(NSString *)reqId
154159
withXLog:(NSString *)xlog
160+
withXVia:(NSString *)xvia
155161
withHost:(NSString *)host
156162
withDuration:(double)duration
157163
withBody:(NSData *)body;

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ - (instancetype)initWithStatus:(int)status
7373
- (instancetype)init:(int)status
7474
withReqId:(NSString *)reqId
7575
withXLog:(NSString *)xlog
76+
withXVia:(NSString *)xvia
7677
withHost:(NSString *)host
7778
withDuration:(double)duration
7879
withBody:(NSData *)body {
7980
if (self = [super init]) {
8081
_statusCode = status;
8182
_reqId = [reqId copy];
8283
_xlog = [xlog copy];
84+
_xvia = [xvia copy];
8385
_host = [host copy];
8486
_duration = duration;
8587
if (status != 200) {
@@ -105,7 +107,7 @@ - (instancetype)init:(int)status
105107
}
106108

107109
- (NSString *)description {
108-
return [NSString stringWithFormat:@"<%@: %p, status: %d, requestId: %@, xlog: %@, host: %@ duration:%f s serverIp:%@ error: %@>", NSStringFromClass([self class]), self, _statusCode, _reqId, _xlog, _host, _duration, _serverIp, _error];
110+
return [NSString stringWithFormat:@"<%@: %p, status: %d, requestId: %@, xlog: %@, xvia: %@, host: %@ duration:%f s serverIp:%@ error: %@>", NSStringFromClass([self class]), self, _statusCode, _reqId, _xlog, _xvia, _host, _duration, _serverIp, _error];
109111
}
110112

111113
- (BOOL)isCancelled {

0 commit comments

Comments
 (0)