Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复回放url拦截问题 #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ + (BOOL)canInitWithRequest:(NSURLRequest *)request {
}

+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
NSMutableURLRequest *mutableReqeust = request.mutableCopy;
__block NSString *mockUrl = nil;
__block NSDictionary *mockResult = nil;
NSString *httpMethod = request.HTTPMethod;
NSArray<PrismBehaviorItemRequestInfoModel*> *requestInfos = [NSURLProtocol propertyForKey:PRISM_REQUEST_INFOS inRequest:request];
NSString *urlFlag = [NSString stringWithFormat:@"%@", request.URL.path];
NSString *urlFlag = [PrismBehaviorReplayManager sharedManager].urlFlagPickBlock ? [PrismBehaviorReplayManager sharedManager].urlFlagPickBlock(request) : nil;
[requestInfos enumerateObjectsUsingBlock:^(PrismBehaviorItemRequestInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.originUrl containsString:urlFlag]) {
/*
Expand All @@ -72,14 +72,11 @@ + (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
}
else {
// 方式一
mockUrl = obj.mockUrl;
mutableReqeust.URL = [NSURL URLWithString:obj.mockUrl];
}
*stop = YES;
}
}];

NSMutableURLRequest *mutableReqeust = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:mockUrl]];
mutableReqeust.HTTPMethod = httpMethod;
[NSURLProtocol setProperty:@(YES) forKey:PRISM_REQUEST_HAS_INIT inRequest:mutableReqeust];
[NSURLProtocol setProperty:mockResult forKey:PRISM_REQUEST_MOCK_RESULT inRequest:mutableReqeust];
request = [mutableReqeust copy];
Expand Down