@@ -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 ];
@@ -46,8 +40,12 @@ + (QNResponseInfo *)buildResponseInfo:(AFHTTPRequestOperation *)operation
4640 NSDictionary *headers = [operation.response allHeaderFields ];
4741 NSString *reqId = headers[@" X-Reqid" ];
4842 NSString *xlog = headers[@" X-Log" ];
43+ NSString *xvia = headers[@" X-Via" ];
44+ if (xvia == nil ) {
45+ xvia = headers[@" X-Px" ];
46+ }
4947 int status = (int )[operation.response statusCode ];
50- 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];
5149 }
5250 else {
5351 info = [QNResponseInfo responseInfoWithNetError: error host: host duration: duration];
@@ -68,10 +66,12 @@ - (void) sendRequest:(NSMutableURLRequest *)request
6866 if (info.isOK ) {
6967 resp = responseObject;
7068 }
69+ NSLog (@" success %@ " , info);
7170 completeBlock (info, resp);
7271 } failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
7372 double duration = [[NSDate date ] timeIntervalSinceDate: startTime];
7473 QNResponseInfo *info = [QNHttpManager buildResponseInfo: operation withError: error withDuration: duration withResponse: operation.responseData];
74+ NSLog (@" failure %@ " , info);
7575 completeBlock (info, nil );
7676 }
7777
@@ -84,7 +84,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
8484 }
8585 [request setTimeoutInterval: kQNTimeoutInterval ];
8686
87- [request setValue: userAgent forHTTPHeaderField: @" User-Agent" ];
87+ [request setValue: QNUserAgent () forHTTPHeaderField: @" User-Agent" ];
8888 [request setValue: nil forHTTPHeaderField: @" Accept-Language" ];
8989 [_httpManager.operationQueue addOperation: operation];
9090}
0 commit comments