diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index a5f65c1..d467e08 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -134,31 +134,7 @@ - (nullable NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error { - NSURL *url = requestParameters.URL; - if (!url) { - if (requestParameters.alternateBaseURL) { - url = requestParameters.alternateBaseURL; - } else { - url = [MVMCoreSessionObject sharedGlobal].baseURL ?: [NSURL URLWithString:URLProdPostpayBase]; - } - - // Appends the context root. - if (requestParameters.contextRoot) { - url = [url URLByAppendingPathComponent:requestParameters.contextRoot]; - } else if ([MVMCoreSessionObject sharedGlobal].contextRoot) { - url = [url URLByAppendingPathComponent:[MVMCoreSessionObject sharedGlobal].contextRoot]; - } - - // Appends the page type - if (requestParameters.pageType) { - url = [url URLByAppendingPathComponent:requestParameters.pageType]; - } - - // This has changed since the initial agreement. Seems server always needs page type now. - /* else if (requestParameters.modules) { - url = [url URLByAppendingPathComponent:KeyModuleMap]; - }*/ - } + NSURL *url = [requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]]; // Adds modules needed to the request parameters. if (requestParameters.modules.count > 0) { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index ee714c3..2c9d340 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -111,6 +111,8 @@ - (void)main { MVMCoreLog(@"Load Operation begun for page type %@, background load %@, delegate %@", self.requestParameters.pageType, @(self.backgroundLoad),self.delegateObject.loadDelegate); + [self.requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]]; + // Always check for cancellation before launching the task. if ([self checkAndHandleForCancellation]) { return; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index 2e52a05..a2ca9bf 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -9,6 +9,7 @@ #import #import +#import // The loading style. // MFLoadStyleDefault: This means it has not been explicitely set by the developer. Standard push. @@ -124,4 +125,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { /// Returns optional and required modules - (nullable NSArray *)allModules; +/// Resolves the URL given the session object and the current request parameters. +- (nonnull NSURL *)resolveURL:(nonnull MVMCoreSessionObject *)sessionObject; + @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index e07070a..899ef5f 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -10,9 +10,12 @@ #import "NSDictionary+MFConvenience.h" #import "MVMCoreJSONConstants.h" #import "MVMCoreViewControllerMappingObject.h" +#import "MVMCoreConstants.h" @interface MVMCoreRequestParameters () +@property (nonatomic, strong, nullable) NSURL *determinedURL; + - (nullable instancetype)initWithExtraParameters:(nullable NSDictionary *)extraParameters; @end @@ -86,6 +89,56 @@ return self; } +- (void)setAlternateBaseURL:(NSURL *)alternateBaseURL { + _alternateBaseURL = alternateBaseURL; + _URL = self.determinedURL; // Reset resolution when changed. +} + +- (void)setPageType:(NSString *)pageType { + _pageType = pageType; + _URL = self.determinedURL; // Reset resolution when changed. +} + +- (void)setContextRoot:(NSString *)contextRoot { + _contextRoot = contextRoot; + _URL = self.determinedURL; // Reset resolution when changed. +} + +- (void)setURL:(NSURL *)URL { + self.determinedURL = URL; // If set directly, this becomes the ultimate URL. + _URL = URL; +} + +- (NSURL *)resolveURL:(MVMCoreSessionObject *)sessionObject { + + if (self.URL) { + // Previously resovled. + return self.URL; + } + + NSURL *url; + if (self.alternateBaseURL) { + url = self.alternateBaseURL; + } else { + url = sessionObject.baseURL ?: [NSURL URLWithString:URLProdPostpayBase]; + } + + // Appends the context root. + if (self.contextRoot) { + url = [url URLByAppendingPathComponent:self.contextRoot]; + } else if (sessionObject.contextRoot) { + url = [url URLByAppendingPathComponent:[MVMCoreSessionObject sharedGlobal].contextRoot]; + } + + // Appends the page type + if (self.pageType) { + url = [url URLByAppendingPathComponent:self.pageType]; + } + + _URL = url; + return url; +} + - (void)addRequestParameters:(nonnull NSDictionary *)parameters { if ([parameters count] > 0) { @@ -152,6 +205,7 @@ copyObject.customTimeoutTime = self.customTimeoutTime; copyObject.backgroundRequest = self.backgroundRequest; copyObject.URL = self.URL; + copyObject.determinedURL = self.determinedURL; copyObject.actionMap = self.actionMap; return copyObject; }