diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 2ed9aec9..ca7a6e34 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -175,6 +175,8 @@ A4F671331BAFC345000E2223 /* NSString+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A4F671311BAFC345000E2223 /* NSString+MASPrivate.m */; }; A858C6651D0978A6001FB9AD /* MASOTPService.h in Headers */ = {isa = PBXBuildFile; fileRef = A858C6631D0978A6001FB9AD /* MASOTPService.h */; }; A858C6661D0978A6001FB9AD /* MASOTPService.m in Sources */ = {isa = PBXBuildFile; fileRef = A858C6641D0978A6001FB9AD /* MASOTPService.m */; }; + A888437E2327858D0005F502 /* MASNetworkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = A888437C2327858C0005F502 /* MASNetworkConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A888437F2327858D0005F502 /* MASNetworkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = A888437D2327858C0005F502 /* MASNetworkConfiguration.m */; }; A898EF632182D30A00CF291B /* MASJWTService.m in Sources */ = {isa = PBXBuildFile; fileRef = A898EF612182D30900CF291B /* MASJWTService.m */; }; A898EF642182D30A00CF291B /* MASJWTService.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF622182D30900CF291B /* MASJWTService.h */; }; A898EF672182D35700CF291B /* MASJWKSet.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF652182D35700CF291B /* MASJWKSet.h */; }; @@ -555,6 +557,8 @@ A4F671311BAFC345000E2223 /* NSString+MASPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MASPrivate.m"; sourceTree = ""; }; A858C6631D0978A6001FB9AD /* MASOTPService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASOTPService.h; sourceTree = ""; }; A858C6641D0978A6001FB9AD /* MASOTPService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASOTPService.m; sourceTree = ""; }; + A888437C2327858C0005F502 /* MASNetworkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASNetworkConfiguration.h; sourceTree = ""; }; + A888437D2327858C0005F502 /* MASNetworkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASNetworkConfiguration.m; sourceTree = ""; }; A898EF612182D30900CF291B /* MASJWTService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASJWTService.m; sourceTree = ""; }; A898EF622182D30900CF291B /* MASJWTService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASJWTService.h; sourceTree = ""; }; A898EF652182D35700CF291B /* MASJWKSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASJWKSet.h; sourceTree = ""; }; @@ -1242,6 +1246,8 @@ C8C32B0C22D706B900D64DF0 /* MASMultiPartFormData.h */, C8C32B0E22D7163100D64DF0 /* MASMultiPartRequestSerializer.h */, C8C32B0F22D7163100D64DF0 /* MASMultiPartRequestSerializer.m */, + A888437C2327858C0005F502 /* MASNetworkConfiguration.h */, + A888437D2327858C0005F502 /* MASNetworkConfiguration.m */, ); path = Network; sourceTree = ""; @@ -1681,6 +1687,7 @@ A4831AEC1BD1A87C007B4AE6 /* MASApplication+MASPrivate.h in Headers */, CB5E4C741C1D26BA001B3B8A /* MASPatchURLRequest.h in Headers */, A42157261BF864590034BDC9 /* MASConfigurationService.h in Headers */, + A888437E2327858D0005F502 /* MASNetworkConfiguration.h in Headers */, CB5E4C701C1D250D001B3B8A /* MASPutURLRequest.h in Headers */, CB6491DE1FE9DAF300281288 /* MQTTCFSocketDecoder.h in Headers */, CB9975461EDF5799006CEBB1 /* MASAuthCredentials+MASPrivate.h in Headers */, @@ -2011,6 +2018,7 @@ CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, CBD25B0A1E78C47C00DFB47F /* JWTCoding.m in Sources */, CBD25B101E78C47C00DFB47F /* JWTErrorDescription.m in Sources */, + A888437F2327858D0005F502 /* MASNetworkConfiguration.m in Sources */, CB5E4C6D1C1D2467001B3B8A /* MASDeleteURLRequest.m in Sources */, A46F49CE1C2F5FC500A4C370 /* MASINetworkReachabilityManager.m in Sources */, A4831AEF1BD1A87C007B4AE6 /* MASAuthenticationProvider+MASPrivate.m in Sources */, diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 90197f61..0521c675 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -641,7 +641,7 @@ + (void)startWithURL:(NSURL *)url completion:(MASCompletionErrorBlock)completion withParameters:urlParameters andHeaders:nil requestType:MASRequestResponseTypeJson - responseType:MASRequestResponseTypeJson isPublic:YES]; + responseType:MASRequestResponseTypeJson isPublic:YES timeoutInterval:MASDefaultNetworkTimeoutConfiguration]; MASSessionDataTaskOperation *dataTaskOperation = [urlSessionManager dataOperationWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nonnull responseObject, NSError * _Nonnull error) { if (error) @@ -926,7 +926,8 @@ + (void)deleteFrom:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"DELETE" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"DELETE" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -971,7 +972,8 @@ + (void)getFrom:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"GET" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"GET" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1015,7 +1017,8 @@ + (void)patchTo:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"PATCH" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"PATCH" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1059,7 +1062,8 @@ + (void)postTo:(NSString *)endPoint isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"POST" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"POST" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1103,7 +1107,8 @@ + (void)putTo:(nonnull NSString *)endPoint isPublic:(BOOL)isPublic completion:(nullable MASResponseInfoErrorBlock)completion { - [MAS httpMethod:@"PUT" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; + [MAS httpMethod:@"PUT" endPoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:[self timeoutIntervalForEndpoint:endPoint] + completion:[MAS parseToEjectURLResponseForCompletionBlock:completion]]; } @@ -1111,6 +1116,11 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj { __block MASResponseObjectErrorBlock blockCompletion = completion; + // If default timeoutInterval override to NetworkConfiguration timeoutInterval. + NSTimeInterval timeoutInterval = + (request.timeoutInterval == MASDefaultNetworkTimeoutConfiguration) ? + [self timeoutIntervalForEndpoint:request.endPoint] : request.timeoutInterval; + [MAS httpMethod:request.httpMethod endPoint:request.endPoint withParameters:request.body @@ -1118,6 +1128,7 @@ + (void)invoke:(nonnull MASRequest *)request completion:(nullable MASResponseObj requestType:request.requestType responseType:request.responseType isPublic:request.isPublic + timeoutInterval:request.timeoutInterval completion:^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { if (blockCompletion) @@ -1144,7 +1155,12 @@ + (void)postMultiPartForm:(nonnull MASRequest *)request constructingBodyWithBloc return; } - [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic constructingBodyBlock:formDataBlock progress:progressBlock completion:completion]; + // If default timeoutInterval override to NetworkConfiguration timeoutInterval. + NSTimeInterval timeoutInterval = + (request.timeoutInterval == MASDefaultNetworkTimeoutConfiguration) ? + [self timeoutIntervalForEndpoint:request.endPoint] : request.timeoutInterval; + + [[MASNetworkingService sharedService] postMultiPartForm:request.endPoint withParameters:request.body andHeaders:request.header requestType:request.requestType responseType:request.responseType isPublic:request.isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock progress:progressBlock completion:completion]; }]; } @@ -1195,6 +1211,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1231,6 +1248,7 @@ + (void)httpMethod:(NSString *)httpMethod __block MASRequestResponseType blockRequestType = requestType; __block MASRequestResponseType blockResponseType = responseType; __block BOOL blockIsPublic = isPublic; + __block NSTimeInterval blockTimeoutInterval = timeoutInterval; // // Validate if new scope has been requested in header @@ -1249,6 +1267,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"GET"]) @@ -1259,6 +1278,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"PATCH"]) @@ -1269,6 +1289,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"POST"]) @@ -1279,6 +1300,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } else if ([blockHttpMethod isEqualToString:@"PUT"]) @@ -1289,6 +1311,7 @@ + (void)httpMethod:(NSString *)httpMethod requestType:blockRequestType responseType:blockResponseType isPublic:blockIsPublic + timeoutInterval:blockTimeoutInterval completion:[MAS parseTargetAPIErrorForCompletionBlock:blockCompletion]]; } }]; @@ -1461,6 +1484,27 @@ + (BOOL)isPublicForEndpoint:(NSString *)endPoint } ++ (NSTimeInterval)timeoutIntervalForEndpoint:(NSString *)endPoint +{ + NSTimeInterval timeoutInterval = MASDefaultNetworkTimeoutConfiguration; + + NSURL *endpointURL = [NSURL URLWithString:endPoint]; + if (endpointURL.scheme && endpointURL.host) + { + MASNetworkConfiguration *networkConfiguration = [MASConfiguration networkConfigurationForDomain:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", endpointURL.scheme, endpointURL.host, endpointURL.port]]]; + timeoutInterval = networkConfiguration.timeoutInterval; + } + else if ([MASConfiguration currentConfiguration]) + { + NSURL *gatewayURL = [MASConfiguration currentConfiguration].gatewayUrl; + MASNetworkConfiguration *networkConfiguration = [MASConfiguration networkConfigurationForDomain:[NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", gatewayURL.scheme, gatewayURL.host, gatewayURL.port]]]; + timeoutInterval = networkConfiguration.timeoutInterval; + } + + return timeoutInterval; +} + + # pragma mark - JWT Signing + (NSString * _Nullable)signWithClaims:(MASClaims *_Nonnull)claims error:(NSError *__nullable __autoreleasing *__nullable)error diff --git a/MASFoundation/Classes/MASError.h b/MASFoundation/Classes/MASError.h index 8a12dbe4..ea6bfe60 100644 --- a/MASFoundation/Classes/MASError.h +++ b/MASFoundation/Classes/MASError.h @@ -99,6 +99,10 @@ typedef NS_ENUM(NSInteger, MASFoundationErrorCode) MASFoundationErrorCodeResponseSerializationFailedToParseResponse = 100407, MASFoundationErrorCodeNetworkSSLAuthenticationChallengeFailure = 100408, + // + // Network Configuration + // + MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration = 100501, // // Application diff --git a/MASFoundation/Classes/_private_/MASConstantsPrivate.h b/MASFoundation/Classes/_private_/MASConstantsPrivate.h index f2c10ce0..931bbb17 100644 --- a/MASFoundation/Classes/_private_/MASConstantsPrivate.h +++ b/MASFoundation/Classes/_private_/MASConstantsPrivate.h @@ -204,6 +204,9 @@ static NSString *_Nonnull const MASUserPhoneRequestResponseKey = @"phone_number" static NSString *_Nonnull const MASUserPictureRequestResponseKey = @"picture"; // string static NSString *_Nonnull const MASUserRefreshTokenRequestResponseKey = @"refresh_token"; // string +// Default network timeout configuration. +static int const MASDefaultNetworkTimeoutConfiguration = 60; + # pragma mark - GrantType Constants diff --git a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m index f77e5b88..173bdbcc 100644 --- a/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m +++ b/MASFoundation/Classes/_private_/categories/NSError+MASPrivate.m @@ -994,6 +994,11 @@ + (NSString *)descriptionForFoundationErrorCode:(MASFoundationErrorCode)errorCod case MASFoundationErrorCodeConfigurationInvalidHostForSecurityConfiguration: return @"Invalid host information for security configuration. NSURL host or port cannot be nil."; case MASFoundationErrorCodeConfigurationInvalidPinningInfoForSecurityConfiguration: return @"Invalid pinning information for security configuration. At least one pinning information should be provided or public PKI should be trusted."; + // + // Network Configuration + // + case MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration: return @"Invalid host information for network configuration. NSURL host or port cannot be nil."; + // // Device // diff --git a/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m b/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m index 746cadce..80289881 100644 --- a/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m +++ b/MASFoundation/Classes/_private_/models/Network/MASRequest+MASPrivate.m @@ -23,6 +23,7 @@ @interface MASRequest () @property (assign, readwrite) BOOL sign; @property (assign, readwrite) MASRequestResponseType requestType; @property (assign, readwrite) MASRequestResponseType responseType; +@property (assign, readwrite) NSTimeInterval timeoutInterval; @end @@ -48,6 +49,7 @@ - (instancetype)initWithBuilder:(MASRequestBuilder *)builder self.header = builder.header; self.body = builder.body; self.query = builder.query; + self.timeoutInterval = builder.timeoutInterval; // diff --git a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h index 31e42df9..a6156105 100644 --- a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h +++ b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.h @@ -17,6 +17,51 @@ @interface MASConfigurationService : MASService + +///-------------------------------------- +/// @name Network Configuration +///-------------------------------------- + +# pragma mark - Network Configuration + +/** +Sets network timeout for specified host in MASNetworkConfiguration object + +@warning Upon SDK initialization, [MASConfiguration currentConfiguration].gatewayUrl's MASNetworkConfiguration object will be overwritten. If primary gateway's network configuration has to be modified, ensure to set network configuration after SDK initialization. +@param networkConfiguration MASNetworkConfiguration object with host, and network configuration values. +*/ ++ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration; + + + +/** + Removes network configuration object based on the domain. + + @param domain NSURL of the domain to delete network configuration. + */ ++ (void)removeNetworkConfigurationForDomain:(NSURL *)domain; + + + +/** + Returns an array of MASNetworkConfiguration objects for each host. + + @return Returns an array of currently active MASNetworkConfigurations. + */ ++ (NSArray *)networkConfigurations; + + + +/** + Returns MASNetworkConfiguration object for a specific domain. + + @param domain NSURL of the domain for the MASNetworkConfiguration object. + @return Returns a MASNetworkConfiguration object for the domain. + */ ++ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain; + + + ///-------------------------------------- /// @name Security Configuration ///-------------------------------------- diff --git a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m index 42a67cf9..0f0aa643 100644 --- a/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m +++ b/MASFoundation/Classes/_private_/services/configuration/MASConfigurationService.m @@ -18,6 +18,7 @@ @implementation MASConfigurationService static NSString *_configurationFileType_ = @"json"; static NSDictionary *_newConfigurationObject_ = nil; static BOOL _newConfigurationDetected_ = NO; +static NSMutableDictionary *_networkConfigurations_; static NSMutableDictionary *_securityConfigurations_; static BOOL _enableIdTokenValidation_ = YES; @@ -80,6 +81,42 @@ + (NSDictionary *)getDefaultConfigurationAsDictionary } +# pragma mark - Network Configuration + ++ (void)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration +{ + if (!_networkConfigurations_) + { + _networkConfigurations_ = [NSMutableDictionary dictionary]; + } + + if ([networkConfiguration.host absoluteString]) + { + [_networkConfigurations_ setObject:networkConfiguration forKey:[networkConfiguration.host absoluteString]]; + } +} + + ++ (void)removeNetworkConfigurationForDomain:(NSURL *)domain +{ + NSURL *thisDomain = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", domain.scheme, domain.host, domain.port]]; + [_networkConfigurations_ removeObjectForKey:[thisDomain absoluteString]]; +} + + ++ (NSArray *)networkConfigurations +{ + return _networkConfigurations_ ? [_networkConfigurations_ allValues] : nil; +} + + ++ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain +{ + NSURL *thisDomain = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", domain.scheme, domain.host, domain.port]]; + return thisDomain ? [_networkConfigurations_ objectForKey:[thisDomain absoluteString]] : nil; +} + + # pragma mark - Security Configuration + (void)setSecurityConfiguration:(MASSecurityConfiguration *)securityConfiguration @@ -281,10 +318,18 @@ - (void)serviceWillStart } } + + NSURL *currentURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", _currentConfiguration.gatewayUrl.scheme, _currentConfiguration.gatewayHostName, _currentConfiguration.gatewayPort]]; + + // + // Construct and set MASNetworkConfiguration for the primary gateway + // + MASNetworkConfiguration *defaultNetworkConfiguration = [[MASNetworkConfiguration alloc] initWithURL:currentURL]; + [MASConfiguration setNetworkConfiguration:defaultNetworkConfiguration error:nil]; + // // Construct and set MASSecurityConfiguration for the primary gateway // - NSURL *currentURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", _currentConfiguration.gatewayUrl.scheme, _currentConfiguration.gatewayHostName, _currentConfiguration.gatewayPort]]; MASSecurityConfiguration *defaultSecurityConfiguration = [[MASSecurityConfiguration alloc] initWithURL:currentURL]; defaultSecurityConfiguration.trustPublicPKI = _currentConfiguration.enabledTrustedPublicPKI; defaultSecurityConfiguration.publicKeyHashes = _currentConfiguration.trustedCertPinnedPublicKeyHashes; diff --git a/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m b/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m index 32e66603..c4769655 100644 --- a/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m +++ b/MASFoundation/Classes/_private_/services/jwt/MASJWTService.m @@ -167,6 +167,7 @@ - (void)loadJWKSAsynchronously:(BOOL)async completion:(MASCompletionErrorBlock)c requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:YES + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion: ^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { @@ -191,6 +192,7 @@ - (void)loadJWKSAsynchronously:(BOOL)async completion:(MASCompletionErrorBlock)c requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:YES + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion: ^(NSDictionary * _Nullable responseInfo, NSError * _Nullable error) { diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h index bc6e40fd..ecca1591 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.h @@ -276,6 +276,40 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP DELETE call from the Gateway. This type of HTTP Method type +* places it's parameters within the NSURL itself as an HTTP query extension as so: +* +* https://:/ +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ +- (void)deleteFrom:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + /** * Request method for an HTTP GET call from the Gateway. This type of HTTP Method type * places it's parameters within the NSURL itself as an HTTP query extension as so: @@ -369,6 +403,41 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP GET call from the Gateway. This type of HTTP Method type +* places it's parameters within the NSURL itself as an HTTP query extension as so: +* +* https://:/ +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ +- (void)getFrom:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + + /** * Request method for an HTTP PATCH call to the Gateway. This type of HTTP Method type * places it's parameters within the HTTP body in www-form-urlencoded format: @@ -468,6 +537,42 @@ typedef NSURLRequest* (^MASSessionDataTaskHTTPRedirectBlock)(NSURLSession *sessi completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP PATCH call to the Gateway. This type of HTTP Method type +* places it's parameters within the HTTP body in www-form-urlencoded format: +* +* +* +* +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ +- (void)patchTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + /** * Request method for an HTTP POST call to the Gateway. This type of HTTP Method type * places it's parameters within the HTTP body in www-form-urlencoded format: @@ -569,6 +674,42 @@ withParameters:(NSDictionary *)parameterInfo completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP POST call to the Gateway. This type of HTTP Method type +* places it's parameters within the HTTP body in www-form-urlencoded format: +* +* +* +* +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ +- (void)postTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + /** * Request method for an HTTP PUT call to the Gateway. This type of HTTP Method type * places it's parameters within the HTTP body in www-form-urlencoded format: @@ -668,10 +809,47 @@ withParameters:(NSDictionary *)parameterInfo completion:(MASResponseInfoErrorBlock)completion; +/** +* Request method for an HTTP PUT call to the Gateway. This type of HTTP Method type +* places it's parameters within the HTTP body in www-form-urlencoded format: +* +* +* +* +* +* @param endPointPath The specific end point path fragment NSString to append to the base +* Gateway URL. +* @param parameterInfo An NSDictionary of key/value parameter values that will go into the +* query portion of the URL. +* @param headerInfo An NSDictionary of key/value header values that will go into the HTTP +* header. +* @param requestType The expected content type encoding for the parameter values. +* @param responseType The expected content type encoding for any response data. +* @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. +* @param timeoutInterval Represents the request's timeout interval, in seconds. +* @param completion An MASResponseInfoErrorBlock type (NSDictionary *responseInfo, NSError *error) that will +* receive the NSDictionary responseInfo and an NSError object if there is a failure. +* +* The responseInfo can have two keys: +* +* MASResponseInfoHeaderInfoKey: the value will be an NSDictionary of key/value pairs from the HTTP header. +* MASResponseInfoBodyInfoKey: the value will be an NSObject of some kind that is expected in the body of +* the particular request (optional) +*/ +- (void)putTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion; + + # pragma mark - HTTP File Requests -- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion; +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion; @end diff --git a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m index 179a31c8..d3e6ffc8 100644 --- a/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m +++ b/MASFoundation/Classes/_private_/services/network/MASNetworkingService.m @@ -976,6 +976,7 @@ - (void)deleteFrom:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -996,6 +997,7 @@ - (void)deleteFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1017,6 +1019,30 @@ - (void)deleteFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} + + +- (void)deleteFrom:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self httpDeleteFrom:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1027,6 +1053,7 @@ - (void)httpDeleteFrom:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); @@ -1044,7 +1071,7 @@ - (void)httpDeleteFrom:(NSString *)endPoint return; } - [self httpRequest:@"DELETE" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"DELETE" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1062,6 +1089,7 @@ - (void)getFrom:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1082,9 +1110,30 @@ - (void)getFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } +- (void)getFrom:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self getFrom:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} - (void)getFrom:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo @@ -1092,6 +1141,7 @@ - (void)getFrom:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1103,6 +1153,7 @@ - (void)getFrom:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1113,6 +1164,7 @@ - (void)httpGetFrom:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); @@ -1130,7 +1182,7 @@ - (void)httpGetFrom:(NSString *)endPoint return; } - [self httpRequest:@"GET" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"GET" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1148,6 +1200,7 @@ - (void)patchTo:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1168,6 +1221,7 @@ - (void)patchTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1189,6 +1243,29 @@ - (void)patchTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} + +- (void)patchTo:(NSString *)endPoint + withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self httpPatchTo:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1199,6 +1276,7 @@ - (void)httpPatchTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1214,7 +1292,7 @@ - (void)httpPatchTo:(NSString *)endPoint return; } - [self httpRequest:@"PATCH" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"PATCH" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1232,6 +1310,7 @@ - (void)postTo:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1252,6 +1331,7 @@ - (void)postTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO + timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1263,6 +1343,29 @@ - (void)postTo:(NSString *)endPoint responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion +{ + //DLog(@"called"); + // + // Just passthrough + // + [self postTo:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} + +- (void)postTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval + completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); // @@ -1274,6 +1377,7 @@ - (void)postTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1284,6 +1388,7 @@ - (void)httpPostTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { //DLog(@"called"); @@ -1301,7 +1406,7 @@ - (void)httpPostTo:(NSString *)endPoint return; } - [self httpRequest:@"POST" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"POST" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } @@ -1319,6 +1424,7 @@ - (void)putTo:(NSString *)endPoint requestType:MASRequestResponseTypeJson responseType:MASRequestResponseTypeJson isPublic:NO +timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } @@ -1339,9 +1445,30 @@ - (void)putTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:NO +timeoutInterval:MASDefaultNetworkTimeoutConfiguration completion:completion]; } +- (void)putTo:(NSString *)endPoint +withParameters:(NSDictionary *)parameterInfo + andHeaders:(NSDictionary *)headerInfo + requestType:(MASRequestResponseType)requestType + responseType:(MASRequestResponseType)responseType + isPublic:(BOOL)isPublic + completion:(MASResponseInfoErrorBlock)completion +{ + // + // Just passthrough + // + [self putTo:endPoint + withParameters:parameterInfo + andHeaders:headerInfo + requestType:requestType + responseType:responseType + isPublic:isPublic + timeoutInterval:MASDefaultNetworkTimeoutConfiguration + completion:completion]; +} - (void)putTo:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo @@ -1349,6 +1476,7 @@ - (void)putTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic +timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1360,6 +1488,7 @@ - (void)putTo:(NSString *)endPoint requestType:requestType responseType:responseType isPublic:isPublic + timeoutInterval:timeoutInterval completion:completion]; } @@ -1370,6 +1499,7 @@ - (void)httpPutTo:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // @@ -1385,11 +1515,11 @@ - (void)httpPutTo:(NSString *)endPoint return; } - [self httpRequest:@"PUT" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic completion:completion]; + [self httpRequest:@"PUT" endPoint:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval completion:completion]; } -- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +- (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion { // // endPoint cannot be nil @@ -1404,11 +1534,11 @@ - (void)postMultiPartForm:(NSString*)endPoint withParameters:(NSDictionary *)par return; } - [self httpFileUploadRequest:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock progress:progress completion:completion]; + [self httpFileUploadRequest:endPoint parameters:parameterInfo headers:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock progress:progress completion:completion]; } -- (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion +- (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock progress:(MASFileRequestProgressBlock)progress completion:(MASResponseObjectErrorBlock)completion { NSMutableDictionary *mutableHeaderInfo = [headerInfo mutableCopy]; @@ -1422,7 +1552,7 @@ - (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)pa mutableHeaderInfo[MASGeoLocationRequestResponseKey] = [[MASLocationService sharedService].lastKnownLocation locationAsGeoCoordinates]; } - request = [MASPostFormURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic constructingBodyBlock:formDataBlock]; + request = [MASPostFormURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval constructingBodyBlock:formDataBlock]; // // Construct MASSessionDataTaskOperation with request, and completion block to handle any responsive re-authentication or re-registration. @@ -1479,7 +1609,8 @@ - (void)httpFileUploadRequest:(NSString *)endPoint parameters:(NSDictionary *)pa } -- (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic completion:(MASResponseInfoErrorBlock)completion +- (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint parameters:(NSDictionary *)parameterInfo headers:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval completion:(MASResponseInfoErrorBlock)completion { // // Update the header @@ -1501,23 +1632,23 @@ - (void)httpRequest:(NSString *)httpMethod endPoint:(NSString *)endPoint paramet // if ([httpMethod isEqualToString:@"DELETE"]) { - request = [MASDeleteURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASDeleteURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"GET"]) { - request = [MASGetURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASGetURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"PATCH"]) { - request = [MASPatchURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASPatchURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"POST"]) { - request = [MASPostURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASPostURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } else if ([httpMethod isEqualToString:@"PUT"]) { - request = [MASPutURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic]; + request = [MASPutURLRequest requestForEndpoint:endPoint withParameters:parameterInfo andHeaders:mutableHeaderInfo requestType:requestType responseType:responseType isPublic:isPublic timeoutInterval:timeoutInterval]; } // diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h index 96f9ef4c..1ee38b57 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASDeleteURLRequest which could be used to create NSURLSessionDataTask. */ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint @@ -40,6 +41,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m index 3e91aa41..eace3350 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASDeleteURLRequest.m @@ -26,6 +26,7 @@ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -50,7 +51,7 @@ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASDeleteURLRequest *request = [MASDeleteURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASDeleteURLRequest *request = [MASDeleteURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method @@ -66,6 +67,7 @@ + (MASDeleteURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h index 62ce7a0e..c72260c7 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASGetURLRequest which could be used to create NSURLSessionDataTask. */ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint @@ -40,6 +41,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m index 74b1d3fb..f262bcb6 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASGetURLRequest.m @@ -26,6 +26,7 @@ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -50,7 +51,7 @@ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASGetURLRequest *request = [MASGetURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASGetURLRequest *request = [MASGetURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method @@ -66,6 +67,7 @@ + (MASGetURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h index 00370698..3c03b416 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASPatchURLRequest which could be used to create NSURLSessionDataTask. */ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint @@ -40,6 +41,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m index 3ab2d9ff..134ba8f4 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPatchURLRequest.m @@ -26,6 +26,7 @@ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -45,7 +46,7 @@ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASPatchURLRequest *request = [MASPatchURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASPatchURLRequest *request = [MASPatchURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method @@ -61,6 +62,7 @@ + (MASPatchURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h index 880a8439..c9f2d8b7 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @interface MASPostFormURLRequest : MASURLRequest -+ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock; ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m index fe2d6a04..c35596cf 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostFormURLRequest.m @@ -15,7 +15,7 @@ @implementation MASPostFormURLRequest -+ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock ++ (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameters:(NSDictionary *)parameterInfo andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic timeoutInterval:(NSTimeInterval)timeoutInterval constructingBodyBlock:(nonnull MASMultiPartFormDataBlock)formDataBlock { // // Adding prefix to the endpoint path @@ -35,7 +35,7 @@ + (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameter // // Create the request // - MASPostFormURLRequest *request = [MASPostFormURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:240]; + MASPostFormURLRequest *request = [MASPostFormURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method @@ -48,6 +48,7 @@ + (MASPostFormURLRequest *)requestForEndpoint:(NSString *)endPoint withParameter // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h index ec4a129e..acefeeb4 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASPostURLRequest which could be used to create NSURLSessionDataTask. */ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint @@ -40,6 +41,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m index 06f16d11..e96cb087 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPostURLRequest.m @@ -26,6 +26,7 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -45,7 +46,7 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASPostURLRequest *request = [MASPostURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASPostURLRequest *request = [MASPostURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method @@ -60,6 +61,7 @@ + (MASPostURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h index abc7f459..f73d1a86 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.h @@ -33,6 +33,7 @@ * @param requestType Represents the expected encoding of the request contents. * @param responseType Represents the excepted encoding of the response contents. * @param isPublic Represents whether to include or exclude necessary credentials of MAG to inject in the header of the request. + * @param timeoutInterval Represents the request's timeout interval, in seconds. * @return MASPutURLRequest which could be used to create NSURLSessionDataTask. */ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint @@ -40,6 +41,7 @@ andHeaders:(NSDictionary *)headerInfo requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType - isPublic:(BOOL)isPublic; + isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval; @end diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m index f3ebba17..85766203 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m +++ b/MASFoundation/Classes/_private_/services/network/requests/MASPutURLRequest.m @@ -26,6 +26,7 @@ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint requestType:(MASRequestResponseType)requestType responseType:(MASRequestResponseType)responseType isPublic:(BOOL)isPublic + timeoutInterval:(NSTimeInterval)timeoutInterval { // // Adding prefix to the endpoint path @@ -45,7 +46,7 @@ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint // // Create the request // - MASPutURLRequest *request = [MASPutURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]; + MASPutURLRequest *request = [MASPutURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]; // // Method @@ -61,6 +62,7 @@ + (MASPutURLRequest *)requestForEndpoint:(NSString *)endPoint // capture request // request.isPublic = isPublic; + request.timeoutInterval = timeoutInterval; request.requestType = requestType; request.responseType = responseType; request.headerInfo = headerInfo; diff --git a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h index 79407d8a..3297d7a3 100644 --- a/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h +++ b/MASFoundation/Classes/_private_/services/network/requests/MASURLRequest.h @@ -27,6 +27,7 @@ @property (assign) BOOL isPublic; @property (assign) MASRequestResponseType requestType; @property (assign) MASRequestResponseType responseType; +@property (assign) NSTimeInterval timeoutInterval; @property (nonatomic, strong) NSString *endPoint; @property (nonatomic, strong) NSDictionary *parameterInfo; @property (nonatomic, strong) NSDictionary *headerInfo; diff --git a/MASFoundation/Classes/models/MASConfiguration.h b/MASFoundation/Classes/models/MASConfiguration.h index 84c07c32..5f694ead 100644 --- a/MASFoundation/Classes/models/MASConfiguration.h +++ b/MASFoundation/Classes/models/MASConfiguration.h @@ -9,6 +9,7 @@ // @import Foundation; +@class MASNetworkConfiguration; @class MASSecurityConfiguration; /** @@ -173,6 +174,50 @@ +///-------------------------------------- +/// @name Network Configuration +///-------------------------------------- + +# pragma mark - Network Configuration + +/** +Sets network timeout for specified host in MASNetworkConfiguration object + +@warning Upon SDK initialization, [MASConfiguration currentConfiguration].gatewayUrl's MASNetworkConfiguration object will be overwritten. If primary gateway's network configuration has to be modified, ensure to set network configuration after SDK initialization. +@param networkConfiguration MASNetworkConfiguration object with host, and network configuration values. +*/ ++ (BOOL)setNetworkConfiguration:(MASNetworkConfiguration *_Nonnull)networkConfiguration error:(NSError *__nullable __autoreleasing *__nullable)error; + + + +/** + Removes network configuration object based on the domain (host, and port number). + + @param domain NSURL object of domain to delete MASNetworkConfiguration. + */ ++ (void)removeNetworkConfigurationForDomain:(NSURL *_Nonnull)domain; + + + +/** + Returns an array of MASNetworkConfiguration objects for each host. + + @return Returns an array of currently active MASNetworkConfigurations. + */ ++ (NSArray *_Nullable)networkConfigurations; + + + +/** + Returns MASSecurityConfiguration object for a specific domain. + + @param domain NSURL of the domain for the MASSecurityConfiguration object. + @return Returns a MASSecurityConfiguration object for the domain. + */ ++ (MASNetworkConfiguration *_Nullable)networkConfigurationForDomain:(NSURL *_Nonnull)domain; + + + ///-------------------------------------- /// @name Security Configuration ///-------------------------------------- diff --git a/MASFoundation/Classes/models/MASConfiguration.m b/MASFoundation/Classes/models/MASConfiguration.m index 4c245d35..34226dba 100644 --- a/MASFoundation/Classes/models/MASConfiguration.m +++ b/MASFoundation/Classes/models/MASConfiguration.m @@ -419,6 +419,49 @@ - (id)initWithCoder:(NSCoder *)aDecoder } +# pragma mark - Network Configuration + ++ (BOOL)setNetworkConfiguration:(MASNetworkConfiguration *)networkConfiguration error:(NSError **)error +{ + // + // Validate the NSURL host for network configuration. + // + if (!networkConfiguration.host || !networkConfiguration.host.port) + { + if (error) + { + *error = [NSError errorForFoundationCode:MASFoundationErrorCodeConfigurationInvalidHostForNetworkConfiguration errorDomain:MASFoundationErrorDomainLocal]; + } + + return NO; + } + + [MASConfigurationService setNetworkConfiguration:networkConfiguration]; + + return YES; +} + + ++ (void)removeNetworkConfigurationForDomain:(NSURL *)domain +{ + [MASConfigurationService removeNetworkConfigurationForDomain:domain]; +} + + ++ (NSArray *)networkConfigurations +{ + return [MASConfigurationService networkConfigurations]; +} + + ++ (MASNetworkConfiguration *)networkConfigurationForDomain:(NSURL *)domain +{ + return [MASConfigurationService networkConfigurationForDomain:domain]; +} + + +# pragma mark - Security Configuration + + (BOOL)setSecurityConfiguration:(MASSecurityConfiguration *)securityConfiguration error:(NSError **)error { // diff --git a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h new file mode 100644 index 00000000..c99d9c16 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.h @@ -0,0 +1,54 @@ +// +// MASNetworkConfiguration.h +// MASFoundation +// +// Copyright © 2019 CA Technologies. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import "MASObject.h" + + +@interface MASNetworkConfiguration : MASObject + + + +///-------------------------------------- +/// @name Properties +///-------------------------------------- + +# pragma mark - Properties + + +/** +The NSTimeInterval value that specifies the global timeInterval of all the requests. +*/ +@property (assign) NSTimeInterval timeoutInterval; + + + +/** + NSURL value of the target host. + */ +@property (nonatomic, strong, readonly, nonnull) NSURL *host; + + + +///-------------------------------------- +/// @name Lifecycle +///-------------------------------------- + +# pragma mark - Lifecycle + +/** + Designated initializer for MASNetworkConfiguration. + + @discussion default values for designated initializer are: timeoutInterval : 60. + @param url NSURL of the target domain + @return MASNetworkConfiguration object + */ +- (instancetype _Nonnull)initWithURL:(NSURL * _Nonnull)url NS_DESIGNATED_INITIALIZER; + +@end diff --git a/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m new file mode 100644 index 00000000..da2b71f2 --- /dev/null +++ b/MASFoundation/Classes/models/Network/MASNetworkConfiguration.m @@ -0,0 +1,40 @@ +// +// MASNetworkConfiguration.m +// MASFoundation +// +// Copyright © 2019 CA Technologies. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import "MASNetworkConfiguration.h" + +#import "MASConstantsPrivate.h" + + +@interface MASNetworkConfiguration () + +@property (nonatomic, strong, readwrite) NSURL *host; + +@end + + +@implementation MASNetworkConfiguration + + +# pragma mark - Lifecycle + +- (instancetype)initWithURL:(NSURL *)url +{ + self = [super init]; + + if (self) { + self.host = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@:%@", url.scheme, url.host, url.port]]; + self.timeoutInterval = MASDefaultNetworkTimeoutConfiguration; + } + + return self; +} + +@end diff --git a/MASFoundation/Classes/models/Network/MASRequest.h b/MASFoundation/Classes/models/Network/MASRequest.h index 5b493627..67d17225 100644 --- a/MASFoundation/Classes/models/Network/MASRequest.h +++ b/MASFoundation/Classes/models/Network/MASRequest.h @@ -84,6 +84,12 @@ @property (assign, readonly) MASRequestResponseType responseType; +/** +The NSTimeInterval value that specifies the timeInterval of the request. +*/ +@property (assign, readonly) NSTimeInterval timeoutInterval; + + # pragma mark - Public diff --git a/MASFoundation/Classes/models/Network/MASRequest.m b/MASFoundation/Classes/models/Network/MASRequest.m index c63179d8..57f1f108 100644 --- a/MASFoundation/Classes/models/Network/MASRequest.m +++ b/MASFoundation/Classes/models/Network/MASRequest.m @@ -22,6 +22,7 @@ @interface MASRequest () @property (assign, readwrite) BOOL sign; @property (assign, readwrite) MASRequestResponseType requestType; @property (assign, readwrite) MASRequestResponseType responseType; +@property (assign, readwrite) NSTimeInterval timeoutInterval; @end diff --git a/MASFoundation/Classes/models/Network/MASRequestBuilder.h b/MASFoundation/Classes/models/Network/MASRequestBuilder.h index 1bdbb6cd..2d12f0cf 100644 --- a/MASFoundation/Classes/models/Network/MASRequestBuilder.h +++ b/MASFoundation/Classes/models/Network/MASRequestBuilder.h @@ -18,6 +18,7 @@ Default configuration value for designated initializer, [[MASRequestBuilder alloc] initWithHTTPMethod:], would be: isPublic: NO, + timeoutInterval: 60, sign: NO, requestType:MASRequestResponseTypeJson, responseType:MASRequestResponseTypeJson. @@ -98,6 +99,12 @@ @property (assign) MASRequestResponseType responseType; +/** +The NSTimeInterval value that specifies the timeInterval of the request. +*/ +@property (assign) NSTimeInterval timeoutInterval; + + ///-------------------------------------- /// @name Lifecycle ///-------------------------------------- diff --git a/MASFoundation/Classes/models/Network/MASRequestBuilder.m b/MASFoundation/Classes/models/Network/MASRequestBuilder.m index b04d6944..34bf0117 100644 --- a/MASFoundation/Classes/models/Network/MASRequestBuilder.m +++ b/MASFoundation/Classes/models/Network/MASRequestBuilder.m @@ -10,8 +10,10 @@ #import "MASRequestBuilder.h" +#import "MASConstantsPrivate.h" #import "MASRequest+MASPrivate.h" + @interface MASRequestBuilder () @property (nonatomic, strong, readwrite) NSString *httpMethod; @@ -36,6 +38,7 @@ - (instancetype)initWithHTTPMethod:(NSString *)method self.sign = NO; self.requestType = MASRequestResponseTypeJson; self.responseType = MASRequestResponseTypeJson; + self.timeoutInterval = MASDefaultNetworkTimeoutConfiguration; // default to 60 seconds. } return self; diff --git a/MASFoundation/MASFoundation.h b/MASFoundation/MASFoundation.h index 9cd5edca..7f36d17b 100644 --- a/MASFoundation/MASFoundation.h +++ b/MASFoundation/MASFoundation.h @@ -24,6 +24,7 @@ FOUNDATION_EXPORT const unsigned char MASFoundationVersionString[]; #import #import #import +#import #import #import #import