Skip to content

Commit 66dc1cd

Browse files
author
Rodrigo Gomez Palacio
committed
Update OneSignalClient to include headers
1 parent 3ae1076 commit 66dc1cd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalClient.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,29 @@ - (void)prettyPrintDebugStatementWithRequest:(OneSignalRequest *)request {
189189
}
190190

191191
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
192-
193-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"HTTP Request (%@) with URL: %@, with parameters: %@", NSStringFromClass([request class]), request.urlRequest.URL.absoluteString, jsonString]];
192+
193+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"HTTP Request (%@) with URL: %@, with parameters: %@ and headers: %@", NSStringFromClass([request class]), request.urlRequest.URL.absoluteString, jsonString, request.additionalHeaders]];
194194
}
195195

196196
- (void)handleJSONNSURLResponse:(NSURLResponse*)response data:(NSData*)data error:(NSError*)error isAsync:(BOOL)async withRequest:(OneSignalRequest *)request onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
197197

198198
NSHTTPURLResponse* HTTPResponse = (NSHTTPURLResponse*)response;
199199
NSInteger statusCode = [HTTPResponse statusCode];
200+
NSDictionary *headers = [HTTPResponse allHeaderFields];
200201
NSError* jsonError = nil;
201202
NSMutableDictionary* innerJson;
202203

203204
if (data != nil && [data length] > 0) {
204205
innerJson = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonError];
205206
innerJson[@"httpStatusCode"] = [NSNumber numberWithLong:statusCode];
207+
innerJson[@"headers"] = headers;
208+
209+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"network request (%@) with URL %@ and headers: %@", NSStringFromClass([request class]), request.urlRequest.URL.absoluteString, request.additionalHeaders]];
210+
206211
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"network response (%@) with URL %@: %@", NSStringFromClass([request class]), request.urlRequest.URL.absoluteString, innerJson]];
207212
if (jsonError) {
208213
if (failureBlock != nil)
209-
failureBlock([NSError errorWithDomain:@"OneSignal Error" code:statusCode userInfo:@{@"returned" : jsonError}]);
214+
failureBlock([NSError errorWithDomain:@"OneSignal Error" code:statusCode userInfo:@{@"returned" : jsonError, @"headers": headers}]); // Add headers to error block
210215
return;
211216
}
212217
}
@@ -224,14 +229,15 @@ - (void)handleJSONNSURLResponse:(NSURLResponse*)response data:(NSData*)data erro
224229
} else if (failureBlock != nil) {
225230
// Make sure to send all the infomation available to the client
226231
if (innerJson != nil && error != nil)
227-
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson, @"error": error}]);
232+
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson, @"error": error, @"headers": headers}]);
228233
else if (innerJson != nil)
229-
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson}]);
234+
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"returned" : innerJson, @"headers": headers}]);
230235
else if (error != nil)
231-
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"error" : error}]);
236+
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"error" : error, @"headers": headers}]);
232237
else
233-
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:nil]);
238+
failureBlock([NSError errorWithDomain:@"OneSignalError" code:statusCode userInfo:@{@"headers": headers}]);
234239
}
235240
}
236241

242+
237243
@end

0 commit comments

Comments
 (0)