Skip to content

Commit

Permalink
- OCHTTPRequest: add support for custom timeouts
Browse files Browse the repository at this point in the history
- OCConnection: increase timeout for infinite PROPFIND to 6 minutes using new custom timeouts, in case a proxy first
  • Loading branch information
felix-schwarz committed Mar 17, 2022
1 parent c778919 commit a4283b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ownCloudSDK/Connection/OCConnection.m
Expand Up @@ -1802,6 +1802,11 @@ - (NSProgress *)retrieveItemListAtPath:(OCPath)path depth:(NSUInteger)depth opti
davRequest.downloadRequest = YES;
davRequest.priority = NSURLSessionTaskPriorityHigh;
davRequest.forceCertificateDecisionDelegation = YES;
if (depth == OCPropfindDepthInfinity)
{
// Extend timeout to 5 minutes for infinite PROPFIND
davRequest.customTimeout = @(5 * 60.0);
}

if (options[OCConnectionOptionRequestObserverKey] != nil)
{
Expand Down
2 changes: 2 additions & 0 deletions ownCloudSDK/HTTP/Request/OCHTTPRequest.h
Expand Up @@ -106,6 +106,8 @@ typedef NSDictionary<OCHTTPRequestResumeInfoKey,id>* OCHTTPRequestResumeInfo;
@property(strong) OCEventTarget *eventTarget; //!< The target the parsed result should be delivered to as an event.
@property(strong) NSDictionary *userInfo; //!< User-info for free use. All contents should be serializable.

@property(strong) NSNumber *customTimeout; //!< Custom timeout in seconds for request.

@property(assign) OCHTTPRequestPriority priority; //!< Priority of the request from 0.0 (lowest priority) to 1.0 (highest priority). Defaults to NSURLSessionTaskPriorityDefault (= 0.5).
@property(strong) OCHTTPRequestGroupID groupID; //!< ID of the Group the request belongs to (if any). Requests in the same group are executed serially, whereas requests that belong to no group are executed as soon as possible.

Expand Down
14 changes: 12 additions & 2 deletions ownCloudSDK/HTTP/Request/OCHTTPRequest.m
Expand Up @@ -281,8 +281,14 @@ - (void)prepareForScheduling
- (NSMutableURLRequest *)generateURLRequest
{
NSMutableURLRequest *urlRequest;

if ((urlRequest = [[NSMutableURLRequest alloc] initWithURL:self.effectiveURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60]) != nil)
NSTimeInterval timeoutInterval = 60;

if (self.customTimeout != nil)
{
timeoutInterval = self.customTimeout.doubleValue;
}

if ((urlRequest = [[NSMutableURLRequest alloc] initWithURL:self.effectiveURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeoutInterval]) != nil)
{
// Apply method
urlRequest.HTTPMethod = self.method;
Expand Down Expand Up @@ -589,6 +595,8 @@ - (instancetype)initWithCoder:(NSCoder *)decoder
self.eventTarget = [decoder decodeObjectOfClass:[OCEventTarget class] forKey:@"eventTarget"];
self.userInfo = [decoder decodeObjectOfClasses:OCEvent.safeClasses forKey:@"userInfo"];

self.customTimeout = [decoder decodeObjectOfClass:NSNumber.class forKey:@"customTimeout"];

self.priority = [decoder decodeFloatForKey:@"priority"];
self.groupID = [decoder decodeObjectOfClass:[NSString class] forKey:@"groupID"];

Expand Down Expand Up @@ -644,6 +652,8 @@ - (void)encodeWithCoder:(NSCoder *)coder
[coder encodeObject:_eventTarget forKey:@"eventTarget"];
[coder encodeObject:_userInfo forKey:@"userInfo"];

[coder encodeObject:_customTimeout forKey:@"customTimeout"];

[coder encodeFloat:_priority forKey:@"priority"];
[coder encodeObject:_groupID forKey:@"groupID"];

Expand Down

0 comments on commit a4283b1

Please sign in to comment.