{"id":27103918,"url":"https://github.com/victorzhang2014/zrurlprotocol","last_synced_at":"2025-08-17T10:41:04.671Z","repository":{"id":129950865,"uuid":"83127654","full_name":"VictorZhang2014/ZRURLProtocol","owner":"VictorZhang2014","description":"ZRURLProtocol is encapsulated of NSURLProtocol which can intercept all request in UIWebView","archived":false,"fork":false,"pushed_at":"2017-02-25T12:00:09.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-12T01:33:40.168Z","etag":null,"topics":["interception-httphttps-request","ios","nsurlprotocol","objective-c"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VictorZhang2014.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-25T11:38:33.000Z","updated_at":"2017-02-25T13:26:53.000Z","dependencies_parsed_at":"2023-03-13T11:18:23.585Z","dependency_job_id":null,"html_url":"https://github.com/VictorZhang2014/ZRURLProtocol","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/VictorZhang2014/ZRURLProtocol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2FZRURLProtocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2FZRURLProtocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2FZRURLProtocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2FZRURLProtocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorZhang2014","download_url":"https://codeload.github.com/VictorZhang2014/ZRURLProtocol/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorZhang2014%2FZRURLProtocol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270837424,"owners_count":24654379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interception-httphttps-request","ios","nsurlprotocol","objective-c"],"created_at":"2025-04-06T17:29:50.338Z","updated_at":"2025-08-17T10:41:04.606Z","avatar_url":"https://github.com/VictorZhang2014.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZRURLProtocol\nZRURLProtocol is encapsulated of NSURLProtocol which can intercept all requests in UIWebView\n\n## Purpose\n\u003e\u003e 1. To intercept all requests in UIWebView \n\u003e\u003e 2. Want to mock/simulate NSURLRequest while requesting in UIWebView\n\u003e\u003e 3. Want to replace some of images in HTML pages requesting by local images\n\n#### Apple Official Demo and Documentation\n- [NSURLProtocol Tutorial in Apple Demo](https://developer.apple.com/library/content/samplecode/CustomHTTPProtocol/Introduction/Intro.html)\n\n### For more details , see \n- [NSURLProtocol Tutorial](https://www.raywenderlich.com/59982/nsurlprotocol-tutorial) \n- [NSURLProtocol Tutorial](http://draveness.me/intercept/) \n\n## Usage\n1. In `AppDelegate.h` file\n```\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n    \n    [ZRURLProtocol start];\n    \n    return YES;\n}\n```\n\n2. Implement two methods in the `ZRURLProtocolDelegate` \n```\n#import \"ViewController.h\"\n#import \"ZRURLProtocol.h\"\n\n@interface ViewController ()\u003cZRURLProtocolDelegate\u003e\n\n@property (nonatomic, strong) UIWebView * webView;\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad {\n    [super viewDidLoad];\n    \n    \n    NSURLRequest * req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@\"http://www.baidu.com\"]];\n    \n    self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];\n    [self.view addSubview:self.webView];\n    [self.webView loadRequest:req];\n    \n    [ZRURLProtocol setDelegate:self];\n    \n}\n\n- (void)URLProtocolEveryURLRequestInWebView:(NSURLRequest *)request\n{\n    //Every URL of the request will be invoked here.\n    NSLog(@\"url=%@\", request.URL.absoluteString);\n}\n\n- (NSURLRequest *)URLProtocolOriginalRequest:(NSURLRequest *)request\n{\n    //1.Returns an new instance of NSURLRequest\n    //2.Modifies the property of @param-request, like header's value or add new header property\n    return request;\n}\n\n@end\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorzhang2014%2Fzrurlprotocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorzhang2014%2Fzrurlprotocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorzhang2014%2Fzrurlprotocol/lists"}