@@ -54,18 +54,14 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
5454@interface QNSessionManager ()
5555@property (nonatomic ) AFHTTPSessionManager *httpManager;
5656@property UInt32 timeout;
57+ @property (nonatomic , strong ) QNUrlConvert converter;
5758@end
5859
59- static NSString *userAgent = nil ;
60-
6160@implementation QNSessionManager
6261
63- + (void )initialize {
64- userAgent = QNUserAgent ();
65- }
66-
6762- (instancetype )initWithProxy : (NSDictionary *)proxyDict
68- timeout : (UInt32)timeout {
63+ timeout : (UInt32)timeout
64+ urlConverter : (QNUrlConvert)converter {
6965 if (self = [super init ]) {
7066 NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration ];
7167 if (proxyDict != nil ) {
@@ -74,13 +70,14 @@ - (instancetype)initWithProxy:(NSDictionary *)proxyDict
7470 _httpManager = [[AFHTTPSessionManager alloc ] initWithSessionConfiguration: configuration];
7571 _httpManager.responseSerializer = [AFHTTPResponseSerializer serializer ];
7672 _timeout = timeout;
73+ _converter = converter;
7774 }
7875
7976 return self;
8077}
8178
8279- (instancetype )init {
83- return [self initWithProxy: nil timeout: 60 ];
80+ return [self initWithProxy: nil timeout: 60 urlConverter: nil ];
8481}
8582
8683+ (QNResponseInfo *)buildResponseInfo : (NSHTTPURLResponse *)response
@@ -153,7 +150,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
153150
154151 [request setTimeoutInterval: _timeout];
155152
156- [request setValue: userAgent forHTTPHeaderField: @" User-Agent" ];
153+ [request setValue: QNUserAgent () forHTTPHeaderField: @" User-Agent" ];
157154 [request setValue: nil forHTTPHeaderField: @" Accept-Language" ];
158155 [uploadTask resume ];
159156}
@@ -166,6 +163,10 @@ - (void)multipartPost:(NSString *)url
166163 withCompleteBlock : (QNCompleteBlock)completeBlock
167164 withProgressBlock : (QNInternalProgressBlock)progressBlock
168165 withCancelBlock : (QNCancelBlock)cancelBlock {
166+ if (_converter != nil ) {
167+ url = _converter (url);
168+ }
169+
169170 NSMutableURLRequest *request = [_httpManager.requestSerializer
170171 multipartFormRequestWithMethod: @" POST"
171172 URLString: url
@@ -187,6 +188,10 @@ - (void) post:(NSString *)url
187188 withCompleteBlock : (QNCompleteBlock)completeBlock
188189 withProgressBlock : (QNInternalProgressBlock)progressBlock
189190 withCancelBlock : (QNCancelBlock)cancelBlock {
191+ if (_converter != nil ) {
192+ url = _converter (url);
193+ }
194+
190195 NSMutableURLRequest *request = [[NSMutableURLRequest alloc ] initWithURL: [[NSURL alloc ] initWithString: url]];
191196 if (headers) {
192197 [request setAllHTTPHeaderFields: headers];
0 commit comments