YH_HTTPRequestOperationManager.m 1.62 KB
//
//  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