Skip to content

Commit 4b54442

Browse files
Use request ID as task description (#1451)
Currently task ID is used as a key in the map. This is OK while there is only one session because task ID is unique inside the session. We are creating separate session for requests with proxy so task ID is not unique anymore. Request ID is unique across the Network instance and task description is available same a the task ID. Relates-To: OLPEDGE-2846 Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
1 parent 8374b1c commit 4b54442

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -127,10 +127,10 @@ - (OLPHttpTask*)taskWithId:(olp::http::RequestId)identifier {
127127
return task;
128128
}
129129

130-
- (OLPHttpTask*)taskWithTaskIdentifier:(NSUInteger)taskId {
130+
- (OLPHttpTask*)taskWithTaskDescription:(NSString*)taskDescription {
131131
OLPHttpTask* task = nil;
132132
@synchronized(_tasks) {
133-
task = self.idTaskMap[@(taskId)];
133+
task = [self.idTaskMap objectForKey:taskDescription];
134134
}
135135
return task;
136136
}
@@ -154,7 +154,7 @@ - (void)removeTaskWithId:(olp::http::RequestId)identifier {
154154
OLPHttpTask* task = _tasks[@(identifier)];
155155
if (task.dataTask) {
156156
[task.dataTask cancel];
157-
[self.idTaskMap removeObjectForKey:@(task.dataTask.taskIdentifier)];
157+
[self.idTaskMap removeObjectForKey:[task createTaskDescription]];
158158
}
159159
[_tasks removeObjectForKey:@(identifier)];
160160
[self.urlSessions removeObjectForKey:@(identifier)];
@@ -176,7 +176,7 @@ - (void)URLSession:(NSURLSession*)session
176176
}
177177

178178
@autoreleasepool {
179-
OLPHttpTask* httpTask = [self taskWithTaskIdentifier:task.taskIdentifier];
179+
OLPHttpTask* httpTask = [self taskWithTaskDescription:task.taskDescription];
180180
if ([httpTask isValid]) {
181181
[httpTask didCompleteWithError:error];
182182
[self removeTaskWithId:httpTask.requestId];
@@ -207,7 +207,7 @@ - (void)URLSession:(NSURLSession*)session
207207

208208
@autoreleasepool {
209209
OLPHttpTask* httpTask =
210-
[self taskWithTaskIdentifier:dataTask.taskIdentifier];
210+
[self taskWithTaskDescription:dataTask.taskDescription];
211211
if ([httpTask isValid] && ![httpTask isCancelled]) {
212212
[httpTask didReceiveResponse:response];
213213
} else {
@@ -236,7 +236,7 @@ - (void)URLSession:(NSURLSession*)session
236236

237237
@autoreleasepool {
238238
OLPHttpTask* httpTask =
239-
[self taskWithTaskIdentifier:dataTask.taskIdentifier];
239+
[self taskWithTaskDescription:dataTask.taskDescription];
240240
if ([httpTask isValid] && ![httpTask isCancelled]) {
241241
[httpTask didReceiveData:data];
242242
} else {
@@ -267,7 +267,7 @@ - (void)URLSession:(NSURLSession*)session
267267
isEqualToString:NSURLAuthenticationMethodServerTrust]) {
268268
if (dataTask) {
269269
OLPHttpTask* httpTask =
270-
[self taskWithTaskIdentifier:dataTask.taskIdentifier];
270+
[self taskWithTaskDescription:dataTask.taskDescription];
271271
if (![httpTask isValid]) {
272272
return;
273273
}
@@ -429,9 +429,9 @@ - (NSURLSession*)urlSessionWithProxy:
429429

430430
- (void)registerDataTask:(NSURLSessionDataTask*)dataTask
431431
forHttpTask:(OLPHttpTask*)httpTask {
432-
NSNumber* identifier = @(dataTask.taskIdentifier);
432+
NSString* identifier = dataTask.taskDescription;
433433
@synchronized(_tasks) {
434-
self.idTaskMap[identifier] = httpTask;
434+
[self.idTaskMap setValue:httpTask forKey:identifier];
435435
}
436436
}
437437

olp-cpp-sdk-core/src/http/ios/OLPHttpTask+Internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,4 +35,6 @@
3535

3636
- (void)didCompleteWithError:(NSError*)error;
3737

38+
- (NSString*)createTaskDescription;
39+
3840
@end

olp-cpp-sdk-core/src/http/ios/OLPHttpTask.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,6 +98,7 @@ - (OLPHttpTaskStatus)run {
9898
@synchronized(self) {
9999
if (!self.isCancelled) {
100100
_dataTask = [_urlSession dataTaskWithRequest:request];
101+
_dataTask.taskDescription = [self createTaskDescription];
101102
}
102103
}
103104

@@ -226,6 +227,10 @@ - (void)didReceiveData:(NSData*)data {
226227
}
227228
}
228229

230+
- (NSString*) createTaskDescription {
231+
return [NSString stringWithFormat:@"%llu", self.requestId];
232+
}
233+
229234
#pragma mark - Inquiry methods
230235

231236
- (BOOL)isValid {

0 commit comments

Comments
 (0)