YH_HTTPRequestOperationManager.m
1.62 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
//
// YH_HTTPRequestOperationManager.m
// YH_Mall
//
// Created by jhsonzhi on 16/7/24.
// Copyright © 2016年 YOHO. All rights reserved.
//
#import "YH_HTTPRequestOperationManager.h"
#import "AFHTTPRequestOperation.h"
#import "YH_HttpDNS.h"
#define YH_ApiHost @"http://dev-api.yohops.com:9999"
@implementation YH_HTTPRequestOperationManager
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
NSURLRequest *resultRequest = request;
if ([[YH_HttpDNS shareInstance].dnsFlag isEqualToString:kHttpDNSOpenMD5]) {
NSString *apihost = [[NSURL URLWithString:YH_ApiHost] host];
if ([[request.allHTTPHeaderFields objectForKey:@"Host"] isEqualToString:apihost]
&& ![request.URL.host isEqualToString:apihost]) {
NSURL *cookieURL = [NSURL URLWithString:YH_ApiHost];
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
NSMutableURLRequest *mutableRequest = [request mutableCopy];
[mutableRequest setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:cookies]];
resultRequest = mutableRequest;
// LogInfo(@"cookie:%@",cookies);
}
}
return [super HTTPRequestOperationWithRequest:resultRequest success:success failure:failure];
}
@end