-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace URLProtocol property setting
- Loading branch information
Showing
7 changed files
with
127 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// SBTRequestProperty.m | ||
// SBTUITestTunnelCommon | ||
// | ||
// Created by tomas on 20/02/24. | ||
// | ||
|
||
#import "include/SBTRequestPropertyStorage.h" | ||
|
||
@implementation SBTRequestPropertyStorage | ||
|
||
static NSMutableDictionary *storage; | ||
static dispatch_queue_t queue; | ||
|
||
+ (void)initialize | ||
{ | ||
if (self == [SBTRequestPropertyStorage class]) { | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
storage = [[NSMutableDictionary alloc] init]; | ||
queue = dispatch_queue_create("com.subito.sbtuitesttunnel.storage.queue", DISPATCH_QUEUE_SERIAL); | ||
}); | ||
} | ||
} | ||
|
||
+ (void)setProperty:(id)property forKey:(nonnull NSString *)key inRequest:(nonnull NSMutableURLRequest *)request | ||
{ | ||
if ([property isKindOfClass:[NSData class]] && ((NSData *)property).length > 16834) { | ||
NSString *uuid = [[NSUUID UUID] UUIDString]; | ||
dispatch_sync(queue, ^{ [storage setObject:property forKey:uuid]; }); | ||
[NSURLProtocol setProperty:uuid forKey:key inRequest:request]; | ||
} else { | ||
[NSURLProtocol setProperty:property forKey:key inRequest:request]; | ||
} | ||
} | ||
|
||
+ (id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request; | ||
{ | ||
id property = [NSURLProtocol propertyForKey:key inRequest:request]; | ||
|
||
__block id result = nil; | ||
|
||
dispatch_sync(queue, ^{ | ||
id property = [NSURLProtocol propertyForKey:key inRequest:request]; | ||
result = [storage objectForKey:property] ?: property; | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
@end |
22 changes: 22 additions & 0 deletions
22
Sources/SBTUITestTunnelCommon/include/SBTRequestPropertyStorage.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// SBTRequestPropertyStorage.h | ||
// Pods | ||
// | ||
// Created by tomas on 20/02/24. | ||
// | ||
|
||
/// This class serves as a wrapper for NSURLProtocol to handle proxy property storage, addressing a limitation of | ||
/// NSURLProtocol which restricts property size to 2^14 bytes. This class stores properties in a separate in memory | ||
/// storage assigning a unique uuid. This uuid is passed to the underlying NSURLProtocol and is used to retrieve the | ||
/// property from the storage when needed. Properties are stored in an NSDictionary with the uuid as the key and the | ||
/// property as the value. If this proves to be excessively optimistic memory wise an on disk storage can be implemented | ||
/// in the future. | ||
|
||
@import Foundation; | ||
|
||
@interface SBTRequestPropertyStorage : NSObject | ||
|
||
+ (void)setProperty:(nonnull id)property forKey:(nonnull NSString *)key inRequest:(nonnull NSMutableURLRequest *)request; | ||
+ (nullable id)propertyForKey:(nonnull NSString *)key inRequest:(nonnull NSURLRequest *)request; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters