in Source/TNLRequestOperation.m [1610:1653]
static void _network_prepStep_authorizeScratchURLRequest(TNLRequestOperation * __nullable const self, tnl_request_preparation_block_t nextBlock)
{
if (!self) {
return;
}
TNLAssert(nextBlock != nil);
TNLAssert([self _network_isPreparing]);
id<TNLRequestAuthorizer> authorizer = self.internalDelegate;
SEL callback = @selector(tnl_requestOperation:authorizeURLRequest:completion:);
if (!authorizer || ![authorizer respondsToSelector:callback]) {
nextBlock();
return;
}
tnl_dispatch_barrier_async_autoreleasing(self->_callbackQueue, ^{
NSString *tag = TAG_FROM_METHOD(authorizer, @protocol(TNLRequestAuthorizer), callback);
[self _updateTag:tag];
[authorizer tnl_requestOperation:self
authorizeURLRequest:[self->_scratchURLRequest copy]
completion:^(NSString *authHeader, NSError *error) {
[self _clearTag:tag];
tnl_dispatch_async_autoreleasing(tnl_network_queue(), ^{
if (![self _network_isPreparing]) {
return;
}
if (error) {
[self _network_fail:TNLErrorCreateWithCodeAndUnderlyingError(TNLErrorCodeRequestOperationFailedToAuthorizeRequest, error)];
return;
}
if (authHeader) {
[self->_scratchURLRequest setValue:(authHeader.length > 0) ? authHeader : nil
forHTTPHeaderField:@"Authorization"];
}
nextBlock();
});
}];
});
}