Adding custom headers to outgoing requests - shrishrirang/azure-mobile-apps-ios-client GitHub Wiki

When using the Azure Mobile Apps iOS Client SDK, you might want to add custom headers to all outgoing requests for scenarios like authentication, etc. The MSFilter protocol allows inspecting / editing HTTP requests and responses, except for login related actions.

The example below illustrates how to add a custom header.

@interface CustomFilter : NSObjet<MSFilter>
// ...
@end

@implementation CustomFilter

- (void)handleRequest:(NSURLRequest *)request next:(MSFilterNextBlock))next response:(MSFilterResponseBlock)response
{
    // Create a mutable copy of the request
    NSMutableURLRequest *customRequest = [request mutableCopy];
    
    // If our custom header does not exist, add it.
    if (!mutableRequest.allHTTPHeaderFields[@"custom-header-key"]) {
        [mutableRequest setValue:@"custom-header-value" forHTTPHeaderField:@"custom-header-key"];
    }

    // Invoke next filter
    next(customRequest, response);
}

Such a filter would edit outgoing requests like API calls, MSTable calls, push, pull, etc but not login.

⚠️ **GitHub.com Fallback** ⚠️