@@ -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}
0 commit comments