The HTTP library used by the Spotify iOS client

Overview

SPTDataLoader

Coverage Status Documentation License CocoaPods Carthage compatible Spotify FOSS Slack Readme Score

Authentication and back-off logic is a pain, let's do it once and forget about it! This is a library that allows you to centralise this logic and forget about the ugly parts of making HTTP requests.

  • πŸ“± iOS 10.0+
  • πŸ’» OS X 10.12+
  • ⌚️ watchOS 3.0+
  • πŸ“Ί tvOS 10.0+

Yet another networking library? Well apart from some unique benefits such as built-in rate limiting and powerful request authentication, a significant benefit for you is that any tagged version has been tested in production. We only tag a new release once it’s been used for two weeks by the Spotify app (which has millions of active users a day). As such you can be sure tagged versions are as stable as possible.

As for Spotify, we wanted a light networking library that we had full control over in order to act fast in squashing bugs, and carefully select the feature we needed and were capable of supporting. The architecture also plays very nicely into our MVVM and view aggregation service architectures at Spotify by tying the lifetime of a request to the view.

Architecture πŸ“

SPTDataLoader is designed as an HTTP stack with 3 additional layers on top of NSURLSession.

  • The Application level, which controls the rate limiting and back-off policies per service, respecting the β€œRetry-After” header and knowing when or not it should retry the request.
  • The User level, which controls the authentication of the HTTP requests.
  • The View level, which allows automatic cancellation of requests the view has made upon deallocation.

Authentication

The authentication in this case is abstract, allowing the creator of the SPTDataLoaderFactory to define their own semantics for token acquisition and injection. It allows for asynchronous token acquisition if the token is invalid that seamlessly integrates with the HTTP request-response pattern.

Back-off policy

The data loader service allows rate limiting of URLs to be set explicitly or to be determined by the server using the β€œRetry-After” semantic. It allows back-off retrying by using a jittered exponential backoff to prevent the thundering hordes creating a request storm after a predictable exponential period has expired.

Installation πŸ—οΈ

SPTDataLoader can be installed in a variety of ways, either as a dynamic framework, a static library, or through a dependency manager such as CocoaPods or Carthage.

Manually

Dynamic Framework

Drag the framework into the β€œFrameworks, Libraries, and Embedded Content” area in the β€œGeneral” section of the target.

Static Library

Drag SPTDataLoader.xcodeproj into your App’s Xcode project and link your app with the library in the β€œBuild Phases” section of the target.

CocoaPods

To integrate SPTDataLoader into your project using CocoaPods, add it to your Podfile:

pod 'SPTDataLoader', '~> 2.1'

Carthage

To integrate SPTDataLoader into your project using Carthage, add it to your Cartfile:

github "spotify/SPTDataLoader" ~> 2.1

Usage example πŸ‘€

For an example of this framework's usage, see the demo application SPTDataLoaderDemo in SPTDataLoader.xcodeproj. Just follow the instructions in ClientKeys.h.

Creating the SPTDataLoaderService

In your app you should only have 1 instance of SPTDataLoaderService, ideally you would construct this in something similar to an AppDelegate. It takes in a rate limiter, resolver, user agent and an array of NSURLProtocols. The rate limiter allows objects outside the service to change the rate limiting for different endpoints, the resolver allows overriding of host names, and the array of NSURLProtocols allows support for protocols other than http/s.

SPTDataLoaderRateLimiter *rateLimiter = [SPTDataLoaderRateLimiter rateLimiterWithDefaultRequestsPerSecond:10.0];
SPTDataLoaderResolver *resolver = [SPTDataLoaderResolver new];
self.service = [SPTDataLoaderService dataLoaderServiceWithUserAgent:@"Spotify-Demo"
                                                        rateLimiter:rateLimiter
                                                           resolver:resolver
                                           customURLProtocolClasses:nil];

Note that you can provide all these as nils if you are so inclined, it may be for the best to use nils until you identify a need for these different configuration options.

Defining your own SPTDataLoaderAuthoriser

If you don't need to authenticate your requests you can skip this. In order to authenticate your requests against a backend, you are required to create an implementation of the SPTDataLoaderAuthoriser, the demo project has an example in its SPTDataLoaderAuthoriserOAuth class. In this example we are checking if the request is for the domain which we are attempting to authenticate for, and then performing the authentication (in this case we are injecting an Auth Token into the HTTP header). This interface is asynchronous to allow you to perform token refreshes while a request is in flight in order to hold it until it is ready to be authenticated. Once you have a valid token you can call the delegate (which in this case will be the factory) in order to inform it that the request has been authenticated. Alternatively if you are unable to authenticate the request tell the delegate about the error.

Creating the SPTDataLoaderFactory

Your app should ideally only create an SPTDataLoaderFactory once your user has logged in or if you require no authentication for your calls. The factory controls the authorisation of the different requests against authoriser objects that you construct.

id<SPTDataLoaderAuthoriser> oauthAuthoriser = [[SPTDataLoaderAuthoriserOAuth alloc] initWithDictionary:oauthTokenDictionary];
self.oauthFactory = [self.service createDataLoaderFactoryWithAuthorisers:@[ oauthAuthoriser ]];

What we are doing here is using an implementation of an authoriser to funnel all the requests created by this factory into these authorisers.

Creating the SPTDataLoader

Your app should create an SPTDataLoader object per view that wants to make requests (e.g. it is best not too share these between classes). This is so when your view model is deallocated the requests made by your view model will also be cancelled.

SPTDataLoader *dataLoader = [self.oauthFactory createDataLoader];

Note that this data loader will only authorise requests that are made available by the authorisers supplied to its factory.

Creating the SPTDataLoaderRequest

In order to create a request the only information you will need is the URL and where the request came from. For more advanced requests see the properties on SPTDataLoaderRequest which let you change the method, timeouts, retries and whether to stream the results.

SPTDataLoaderRequest *request = [SPTDataLoaderRequest requestWithURL:meURL
                                                    sourceIdentifier:@"playlists"];
[self.dataLoader performRequest:request];

After you have made the request your data loader will call its delegate regarding results of the requests.

Handling Streamed Requests

Sometimes you will want to process HTTP requests as they come in packet by packet rather than receive a large callback at the end, this works better for memory and certain forms of media. For Spotify's purpose, it works for streaming MP3 previews of our songs. An example of using the streaming API:

void AudioSampleListener(void *, AudioFileStreamID, AudioFileStreamPropertyID, UInt32 *);
void AudioSampleProcessor(void *, UInt32, UInt32, const void *, AudioStreamPacketDescription *);

- (void)load
{
    NSURL *URL = [NSURL URLWithString:@"http://i.spotify.com/mp3_preview"];
    SPTDataLoaderRequest *request = [SPTDataLoaderRequest requestWithURL:URL sourceIdentifier:@"preview"];
    request.chunks = YES;
    [self.dataLoader performRequest:request];
}

- (void)dataLoader:(SPTDataLoader *)dataLoader
didReceiveDataChunk:(NSData *)data
       forResponse:(SPTDataLoaderResponse *)response
{
    void *mp3Data = calloc(data.length, 1);
    memcpy(mp3Data, data.bytes, data.length);
    AudioFileStreamParseBytes(_audioFileStream, data.length, mp3Data, 0);
    free(mp3Data);
}

- (void)dataLoader:(SPTDataLoader *)dataLoader didReceiveInitialResponse:(SPTDataLoaderResponse *)response
{
    AudioFileStreamOpen((__bridge void *)self,
                        AudioSampleListener,
                        AudioSampleProcessor,
                        kAudioFileMP3Type,
                        &_audioFileStream);
}

- (BOOL)dataLoaderShouldSupportChunks:(SPTDataLoader *)dataLoader
{
    return YES;
}

Be sure to render YES in your delegate to tell the data loader that you support chunks, and to set the requests chunks property to YES.

Rate limiting specific endpoints

If you specify a rate limiter in your service, you can give it a default requests per second metric which it applies to all requests coming out your app. (See β€œCreating the SPTDataLoaderService”). However, you can also specify rate limits for specific HTTP endpoints, which may be useful if you want to forcefully control the rate at which clients can make requests to a backend that does large amounts of work.

SPTDataLoaderRateLimiter *rateLimiter = [SPTDataLoaderRateLimiter rateLimiterWithDefaultRequestsPerSecond:10.0];
NSURL *URL = [NSURL URLWithString:@"http://www.spotify.com/thing/thing"];
[rateLimiter setRequestsPerSecond:1 forURL:URL];

It should be noted that when you set the requests per second for a URL, it takes the host, and the first component of the URL and rate limits everything that fits that description.

Switching Hosts for all requests

The SPTDataLoaderService takes in a resolver object as one of its arguments. If you choose to make this non-nil, then you can switch the hosts of different requests as they come in. At Spotify we have a number of DNS matches our requests can go through, giving us backups and failsafes in case one of these machines go down. These operations happen in the SPTDataLoaderResolver, where you can specify a number of alternative addresses for the host. An example of Spotify specifying alternative endpoints for its hosts could be:

SPTDataLoaderResolver *resolver = [SPTDataLoaderResolver new];
NSArray *alternativeAddresses = @[ @"spotify.com",
                                   @"backup.spotify.com",
                                   @"backup2.spotify.com",
                                   @"backup3.spotify.com",
                                   @"192.168.0.1",
                                   @"final.spotify.com" ];
[resolver setAddresses:alternativeAddresses forHost:@"spotify.com"];

This allows any request made to spotify.com to use any one of these other addresses (in this order) if spotify.com becomes unreachable.

Using the jittered exponential timer

This library contains a class called SPTDataLoaderExponentialTimer which it uses internally to perform backoffs with retries. The reason it is jittered is to prevent the "predictable thundering hoardes" from hammering our services if one of them happens to go down. In order to make use of this class, there are some do's and don'ts. For example, do not initialise the class like so:

SPTDataLoaderExponentialTimer *timer = [SPTDataLoaderExponentialTimer exponentialTimerWithInitialTime:0.0
                                                                                              maxTime:10.0];
NSTimeInterval backoffTime = 0.0;
for (int i = 0; i < 1000; ++i) {
    backoffTime = timer.timeIntervalAndCalculateNext;
}

This will result in the backoffTime remaining at 0. Why? Because 0.0 multiplied by an exponential number is still 0. A good initial time might be 0.5 or 1.0 seconds. You will also notice that the backoffTime will get further away from the raw exponential time the more times you calculate the next interval:

SPTDataLoaderExponentialTimer *timer = [SPTDataLoaderExponentialTimer exponentialTimerWithInitialTime:1.0
                                                                                              maxTime:1000.0];
NSTimeInterval backoffTime = 0.0;
for (int i = 0; i < 1000; ++i) {
    backoffTime = timer.timeIntervalAndCalculateNext;
}

This will result in a backoffTime that has drifted far away from its vanilla exponential calculation. Why? Because we add a random jitter to the calculations in order to prevent clients from connecting at the same time, in order to spread the load out evenly when experiencing a reconnect storm. The jitter gets greater along with the exponent.

Consumption observation

SPTDataLoaderService allows you to add a consumption observer whose purpose is to monitor the data consumption of the service for both uploads and downloads. This object must conform to the SPTDataLoaderConsumptionObserver protocol. This is quite easy considering it is a single method like so:

- (void)load
{
    [self.service addConsumptionObserver:self];
}

- (void)unload
{
    [self.service removeConsumptionObserver:self];
}

- (void)endedRequestWithResponse:(SPTDataLoaderResponse *)response
                 bytesDownloaded:(int)bytesDownloaded
                   bytesUploaded:(int)bytesUploaded
{
    NSLog(@"Bytes Downloaded: %d", bytesDownloaded);
    NSLog(@"Bytes Uploaded: %d", bytesUploaded);
}

Also note that this isn't just the payload, it also includes the headers.

Creating a custom authoriser

The SPTDataLoader architecture is designed to centralise authentication around the user level (in this case represented by the factory). In order to do that you must inject an authoriser you made yourself into the factory when it is created. An authoriser in most cases will be injecting an Authorisation header into any request it wants to authorise. An example below shows how a standard authoriser might be constructed for an OAuth flow.

@synthesize delegate = _delegate;

- (NSString *)identifier
{
    return @"OAuth";
}

- (BOOL)requestRequiresAuthorisation:(SPTDataLoaderRequest *)request
{
    // Here we check the hostname to see if it one of the hostnames we authorise against
    // It is also advisable to check whether we are using HTTPS, if we are not we should not inject our Authorisation
    // header in order to keep it secret from prying eyes
    return [request.URL.host isEqualToString:@"myauth.com"] && [request.URL.scheme isEqualToString:@"https"];
}

- (void)authoriseRequest:(SPTDataLoaderRequest *)request
{
    [request addValue:@"My Token" forHeader:@"Authorization"];
    [self.delegate dataLoaderAuthoriser:self authorisedRequest:request];
}

- (void)requestFailedAuthorisation:(SPTDataLoaderRequest *)request response:(SPTDataLoaderResponse *)response
{
    // This tells us that the server returned a 400 error code indicating that the authorisation did not work
    // Commonly this means you should attempt to get another authorisation token
    // Or the response object should be inspected for additional information from the backend
}

- (void)refresh
{
    // Forces a refresh of the authorisation token
}

As you can see all we are doing here is playing with the headers. It should be noted that if you receive an authoriseRequest: call the rest of the request will not execute until you have either sent the delegate a signal telling it the request has been authorised or failed to be authorised.

Swift overlay

Additional APIs that enhance usage within Swift applications are available through the SPTDataLoaderSwift library.

// Creating a DataLoader instance
let dataLoader = dataLoaderFactory.makeDataLoader(/* optional */responseQueue: myCustomQueue)

// Creating a Request instance -- all functions can be chained
let request = dataLoader.request(modelURL, sourceIdentifier: "model-page")

// Modifying the request properties
request.modify { request in
    request.body = modelData
    request.method = .patch
    request.addValue("application/json", forHeader: "Accept")
}

// Adding a response validator
request.validate { response in
    guard response.statusCode.rawValue == 200 else {
        throw ValidationError.badStatus(code: response.statusCode.rawValue)
    }
}

// Adding a response serializer (and executing the request)
request.responseDecodable { response in
    modelResultHandler(response.result)
}

// Cancelling the request
request.cancel()

You can also define serializers to handle custom data types:

struct ProtobufResponseSerializer<Message: SwiftProtobuf.Message>: ResponseSerializer {
    func serialize(response: SPTDataLoaderResponse) throws -> Message {
        guard response.error == nil else {
            throw response.error.unsafelyUnwrapped
        }

        guard let data = response.body else {
            throw ResponseSerializationError.dataNotFound
        }

        return try Message(serializedData: data)
    }
}

let modelSerializer = ProtobufResponseSerializer<MyCustomModel>()
request.responseSerializable(serializer: modelSerializer) { response in
    modelResultHandler(response.result)
}

Background story πŸ“–

At Spotify we have begun moving to a decentralised HTTP architecture, and in doing so have had some growing pains. Initially we had a data loader that would attempt to refresh the access token whenever it became invalid, but we immediately learned this was very hard to keep track of. We needed some way of injecting this authorisation data automatically into a HTTP request that didn't require our features to do any more heavy lifting than they were currently doing.

Thus we came up with a way to elegantly inject tokens in a Just-in-time manner for requests that require them. We also wanted to learn from our mistakes with our proprietary protocol, and bake in back-off policies early to avoid us DDOSing our own backends with huge amounts of eronious requests.

Documentation πŸ“š

See the SPTDataLoader documentation on CocoaDocs.org for the full documentation.

You can also add it to Dash if you want to, using the following Dash feed:

dash-feed://http%3A%2F%2Fcocoadocs.org%2Fdocsets%2FSPTDataLoader%2FSPTDataLoader.xml

Contributing πŸ“¬

Contributions are welcomed, have a look at the CONTRIBUTING.md document for more information.

License πŸ“

The project is available under the Apache 2.0 license.

Comments
  • Add a build step which validates each source file for the inclusion of our license header

    Add a build step which validates each source file for the inclusion of our license header

    This PR adds a build step which validates that all source files contains our license header. The script did find a few files which where missing it :smile:

    It also adds Travis-CI group folding to our different steps, to make the output pretties and easier to find.

    Credits for the nice little diff command goes to @dflems :tada:

    Example output

    Validating source files for license compliance…
    βœ“    "demo/AppDelegate.h"
    βœ“    "demo/ClientKeys.h"
    βœ“    "demo/NSString+OAuthBlob.h"
    βœ“    "demo/PlaylistsViewController.h"
    βœ“    "demo/PlaylistsViewModel.h"
    βœ“    "demo/SPTDataLoaderAuthoriserOAuth.h"
    βœ“    "demo/ViewController.h"
    βœ“    "demo/AppDelegate.m"
    βœ“    "demo/NSString+OAuthBlob.m"
    βœ“    "demo/PlaylistsViewController.m"
    βœ“    "demo/PlaylistsViewModel.m"
    βœ“    "demo/SPTDataLoaderAuthoriserOAuth.m"
    βœ“    "demo/ViewController.m"
    βœ“    "demo/main.m"
    βœ“    "include/SPTDataLoader/SPTCancellationToken.h"
    βœ“    "include/SPTDataLoader/SPTDataLoader.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderAuthoriser.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderConsumptionObserver.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderConvenience.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderDelegate.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderExponentialTimer.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderFactory.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderRateLimiter.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderRequest.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderResolver.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderResponse.h"
    βœ“    "include/SPTDataLoader/SPTDataLoaderService.h"
    βœ“    "SPTDataLoader/NSDictionary+HeaderSize.h"
    βœ“    "SPTDataLoader/SPTCancellationTokenFactory.h"
    βœ“    "SPTDataLoader/SPTCancellationTokenFactoryImplementation.h"
    βœ“    "SPTDataLoader/SPTCancellationTokenImplementation.h"
    βœ“    "SPTDataLoader/SPTDataLoader+Private.h"
    βœ“    "SPTDataLoader/SPTDataLoaderFactory+Private.h"
    βœ“    "SPTDataLoader/SPTDataLoaderRequest+Private.h"
    βœ“    "SPTDataLoader/SPTDataLoaderRequestResponseHandler.h"
    βœ“    "SPTDataLoader/SPTDataLoaderRequestTaskHandler.h"
    βœ“    "SPTDataLoader/SPTDataLoaderResolverAddress.h"
    βœ“    "SPTDataLoader/SPTDataLoaderResponse+Private.h"
    βœ“    "SPTDataLoader/NSDictionary+HeaderSize.m"
    βœ“    "SPTDataLoader/SPTCancellationTokenFactoryImplementation.m"
    βœ“    "SPTDataLoader/SPTCancellationTokenImplementation.m"
    βœ“    "SPTDataLoader/SPTDataLoader.m"
    βœ“    "SPTDataLoader/SPTDataLoaderExponentialTimer.m"
    βœ“    "SPTDataLoader/SPTDataLoaderFactory.m"
    βœ“    "SPTDataLoader/SPTDataLoaderRateLimiter.m"
    βœ“    "SPTDataLoader/SPTDataLoaderRequest.m"
    βœ“    "SPTDataLoader/SPTDataLoaderRequestTaskHandler.m"
    βœ“    "SPTDataLoader/SPTDataLoaderResolver.m"
    βœ“    "SPTDataLoader/SPTDataLoaderResolverAddress.m"
    βœ“    "SPTDataLoader/SPTDataLoaderResponse.m"
    βœ“    "SPTDataLoader/SPTDataLoaderService.m"
    βœ“    "SPTDataLoaderTests/NSURLSessionDataTaskMock.h"
    βœ“    "SPTDataLoaderTests/NSURLSessionMock.h"
    βœ“    "SPTDataLoaderTests/NSURLSessionTaskMock.h"
    βœ“    "SPTDataLoaderTests/SPTCancellationTokenDelegateMock.h"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderAuthoriserMock.h"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderConsumptionObserverMock.h"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderDelegateMock.h"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRequestResponseHandlerDelegateMock.h"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRequestResponseHandlerMock.h"
    βœ“    "SPTDataLoaderTests/NSDictionaryHeaderSizeTest.m"
    βœ“    "SPTDataLoaderTests/NSURLSessionDataTaskMock.m"
    βœ“    "SPTDataLoaderTests/NSURLSessionMock.m"
    βœ“    "SPTDataLoaderTests/NSURLSessionTaskMock.m"
    βœ“    "SPTDataLoaderTests/SPTCancellationTokenDelegateMock.m"
    βœ“    "SPTDataLoaderTests/SPTCancellationTokenFactoryImplementationTest.m"
    βœ“    "SPTDataLoaderTests/SPTCancellationTokenImplementationTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderAuthoriserMock.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderConsumptionObserverMock.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderDelegateMock.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderExponentialTimerTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderFactoryTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRateLimiterTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRequestResponseHandlerDelegateMock.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRequestResponseHandlerMock.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRequestTaskHandlerTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderRequestTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderResolverAddressTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderResolverTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderResponseTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderServiceTest.m"
    βœ“    "SPTDataLoaderTests/SPTDataLoaderTest.m"
    
    βœ“ [SUCCESS] All source files contains the required license.
    
    enhancement ci 
    opened by rastersize 9
  • Introduce Swift-only request APIs

    Introduce Swift-only request APIs

    These changes take the idea behind SPTDataLoaderBlockWrapper.m and expand upon it to provide protocol-oriented APIs that better utilize Swift language features.

    Example Usage

    struct Album: Decodable {
        let title: String
        let artistName: String
    }
    
    let dataLoader = dataLoaderFactory.makeDataLoader()
    let request = SPTDataLoaderRequest(url: albumURL, sourceIdentifier: "album-feature")
    
    dataLoader.request(request) { (response: Response<Album, Error>) in
        switch response.result {
        case .success(let album):
            print("Loaded album: \(album.title) by \(album.artistName)"
        case .failure(let error):
            print("Failed to load album: \(error)")
        }
    }
    

    Adding Custom Response Serializer

    import SwiftProtobuf
    
    struct ProtobufResponseSerializer<Message: SwiftProtobuf.Message>: ResponseSerializer {
        func serialize(response: SPTDataLoaderResponse) throws -> Message {
            if let error = response.error {
                throw error
            }
    
            return try Message(serializedData: response.body ?? Data())
        }
    }
    
    extension DataLoader {
        @discardableResult
        func request<Message: SwiftProtobuf.Message>(
            _ request: SPTDataLoaderRequest,
            completionHandler: @escaping (Response<Message, Error>) -> Void
        ) -> SPTDataLoaderCancellationToken? {
            let serializer = ProtobufResponseSerializer<Message>()
    
            return self.request(request, serializer: serializer, completionHandler: completionHandler)
        }
    }
    
    opened by kmcbride 8
  • @synthesize of 'weak' property is only allowed in ARC or GC mode

    @synthesize of 'weak' property is only allowed in ARC or GC mode

    /MusiXmatch/3rdParty/SPTDataLoader/SPTDataLoader/SPTDataLoaderCancellationTokenImplementation.m:57:13: @synthesize of 'weak' property is only allowed in ARC or GC mode
    

    Is the library a ARC project?

    question build system 
    opened by loretoparisi 8
  • Implement -debugDescription for Request and Response

    Implement -debugDescription for Request and Response

    Implement -debugDescription methods for SPTDataLoaderRequest and SPTDataLoaderResponse.

    Format of the output is the same as NSURLResponse and NSURLRequest.

    enhancement 
    opened by ChocoChipset 7
  • Add an option to use background session.

    Add an option to use background session.

    What has changed I added a new initializers to the session selector and the data loader service to enable background networking.

    Why this was changed Using background sessions together with download tasks is necessary for networking on watchOS. See details here.

    opened by aniakorolova 6
  • Fix nil-returns from methods with nonnull return type

    Fix nil-returns from methods with nonnull return type

    Caught by running the analyzer bundled with Xcode 7.3 beta 3. Most of the problems were due to the early-return segment of the init methods: early return nil analyzer warning

    Also fixed a the type of some methods that should return nil as well as updated the documentation for those.

    @spotify/objc-dev

    bug fix 
    opened by rastersize 6
  • Allow performing requests for URLs that do not contain a host

    Allow performing requests for URLs that do not contain a host

    Certain URL types supported by NSURLSession are valid even though they do not contain a host property. Previously, the data loader would not even attempt to request these URLs. With this change it is possible to load local files as well as data URIs.

    opened by kmcbride 5
  • Don't use enumerateByteRangesUsingBlock

    Don't use enumerateByteRangesUsingBlock

    This is basically a revert for https://github.com/spotify/SPTDataLoader/commit/844112c2a56adcf5889af91b49ebd1ad21befe17

    It is actually not clear how enumerateByteRangesUsingBlock can fix any crash there but on the other hand is causing unnecessary callback and delay in data delivering.

    opened by gitrema 5
  • SSL Pinning

    SSL Pinning

    Nice work on SPTDataLoader. I'm curious what thoughts around SSL Pinning might be.

    I'm likely to hack something together on a fork the moment, but I would like to contribute back something that is usable for others.

    Any opinions?

    opened by colinmcardell 5
  • Add testErrorDelegateCallbackWhenMismatchInChunkSupport

    Add testErrorDelegateCallbackWhenMismatchInChunkSupport

    • Test that an error is thrown when the data loader attempts to load a request that requires chunks but the delegate does not support chunks
    • Removes previous assertion in favor of a less noisy delegate error callback approach
    unit test 
    opened by 8W9aG 5
  • Simplify slather + coveralls

    Simplify slather + coveralls

    We were calling slather twice. The second time, ignore wasn't set properly, so system framework coverage data was being posted to coveralls. This PR should simplify things. If this works, we can close #11.

    opened by dflems 5
Releases(2.2.0)
  • 2.2.0(Jun 3, 2022)

    Added

    • Added SPTDataLoaderSwift convenience methods for accessing active requests
    • Added SPTDataLoaderSwift response code validators
    • Added SPTDataLoaderSwift wrappers for Concurrency and Combine
    • Added Xcode 13 support

    Fixed

    • Fixed invalid response body for retried requests

    Changed

    • Changed SPTDataLoaderSwift to ignore status code related errors by default
    • Changed SPTDataLoaderSwift to allow throwing errors within a request modifier
    • Changed chunked responses to use the unenumerated data

    Full Changelog: https://github.com/spotify/SPTDataLoader/compare/2.1.1...2.2.0

    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(Feb 17, 2021)

  • 2.1.0(Feb 16, 2021)

    Added

    • Added SPTDataLoaderBlockWrapper callback API
    • Added SPTDataLoaderSwift overlay
    • Added Xcode 12 support

    Changed

    • Changed Accept-Language header to remove duplicates
    • Changed modules to be disabled by default for static library and test targets

    Full Changelog: https://github.com/spotify/SPTDataLoader/compare/2.0.0...2.1.0

    Source code(tar.gz)
    Source code(zip)
    SPTDataLoader-2.1.0.zip(9.74 MB)
  • 1.1.1(Oct 20, 2016)

    Added

    • Added support for SSL pinning.
    • Added iOS 10 support.

    Fixed

    • Fixed nil URLs in the rate limiter causing a crash.
    • Fixed requests executing after they have been cancelled due to a race condition.
    • Fixed unique identifiers incrementing by 2 on every request made.

    Removed

    • Removed iOS 7.0 support.

    Full Changelog: https://github.com/spotify/SPTDataLoader/compare/1.1.0...1.1.1

    Source code(tar.gz)
    Source code(zip)
    SPTDataLoader.framework.zip(3.94 MB)
  • 1.1.0(Feb 15, 2016)

    Watch the loader on your TV. In other words, the watchOS and tvOS release :watch: :tv:

    Added

    • Added support for watchOS and tvOS.
    • Added error handling when a chunked request is made without the delegate supporting chunks.

    Fixed

    • Fixed HTTP errors not being correctly reported if they are not above the 400 HTTP status codes.
    • Fixed a bug allowing infinite retries of requests.

    Removed

    • Removed the non-optional status of cancellation callbacks in the delegate.

    Changed

    • Changed Accept-Language values to be publically accessible.
    • Changed blanket HTTPS certificate accepting a runtime variable rather than a preprocessor macro.
    • Changed the name of SPTCancellationToken to SPTDataLoaderCancellationToken.

    Full Changelog: https://github.com/spotify/SPTDataLoader/compare/1.0.1...1.1.0

    Source code(tar.gz)
    Source code(zip)
    SPTDataLoader.framework.zip(4.08 MB)
  • 1.0.1(Dec 22, 2015)

    Added

    • Added an option to skip NSURLCache.
    • Added absolute timeouts regardless of retries.
    • Added a build flag option that can allow SPTDataLoader to ignore valid HTTPS certificates.
    • Added source identifiers to request objects (for view based tracking of HTTP usage).
    • Added support for custom URL protocols.
    • Added clang module support.
    • Added Accept-Language headers to all requests.
    • Added redirection limit.
    • Added sending the response rather than the request in the SPTDataLoaderConsumer protocol.

    Fixed

    • Fixed a crash that can occur occasionally when copying data from NSURLSession.
    • Fixed Xcode 6.2 project warnings.
    • Fixed retry timeouts from firing constantly when certain conditions are met.
    • Fixed Xcode 6.3 project warnings.
    • Fixed crashes that can occur when calling SPTDataLoader from multiple threads.
    • Fixed swallowing 401s if retrying is not possible.
    • Fixed Xcode 7 warnings.
    • Fixed HTTP redirects not working.

    Full Changelog: https://github.com/spotify/SPTDataLoader/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Feb 2, 2015)

Owner
Spotify
Spotify
Http - Demo for Http Layer

http Example To run the example project, clone the repo, and run pod install fro

null 0 Jan 24, 2022
πŸ“‘ RealHTTP is a lightweight yet powerful client-side HTTP library.

RealHTTP RealHTTP is a lightweight yet powerful client-side HTTP library. Our goal is make an easy to use and effortless http client for Swift. Featur

Immobiliare Labs 233 Jan 7, 2023
A barebones Swift HTTP client with automatic JSON response parsing.

HTTP Client A barebones Swift HTTP client with automatic JSON response parsing. Installation Add HTTP Client as a dependency through Xcode or directly

Joe Masilotti 30 Oct 11, 2022
A simple GCD based HTTP client and server, written in 'pure' Swift

SwiftyHTTP Note: I'm probably not going to update this any further - If you need a Swift networking toolset for the server side, consider: Macro.swift

Always Right Institute 116 Aug 6, 2022
Postie - The Next-Level HTTP API Client using Combine

Postie - The Next-Level HTTP API Client using Combine Postie is a pure Swift library for building URLRequests using property wrappers.

kula 28 Jul 23, 2022
HTTPClient - HTTP Client With Swift

HTTPClient Ex. Search Repository import HTTPClient let url: URL = .init(string:

zunda 1 Jul 20, 2022
Cross-platform JsonRPC client implementation with HTTP and WebSocket support

JsonRPC.swift Cross-platform JsonRPC client implementation with HTTP and WebSocket support Getting started Installation Package Manager Add the follow

Tesseract 5 Oct 19, 2022
SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Tim Wise 4 Oct 25, 2021
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
QwikHttp is a robust, yet lightweight and simple to use HTTP networking library for iOS, tvOS and watchOS

QwikHttp is a robust, yet lightweight and simple to use HTTP networking library. It allows you to customize every aspect of your http requests within a single line of code, using a Builder style syntax to keep your code super clean.

Logan Sease 2 Mar 20, 2022
A simple, lighweight library for making http requets in iOS

HttpKIT Super simple, super lighweight library for making http requets in IOS. It is a work in progress so PR's are definitelty welcome and highly enc

null 0 Dec 5, 2021
A frida tool that capture GET/POST HTTP requests of iOS Swift library 'Alamofire' and disable SSL Pinning.

FridaHookSwiftAlamofire A frida tool that capture GET/POST HTTP requests of iOS Swift library 'Alamofire' and disable SSL Pinning. δΈ­ζ–‡ζ–‡ζ‘£εŠθΏ‡η¨‹ Features Ca

neilwu 69 Dec 16, 2022
Twitter-Client - A twitter client that allow users to view tweets on their iphone

Project 3 - Twitter Client Name of your app is a basic twitter app to read your

null 0 Feb 7, 2022
πŸ‡ A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

John Lui 845 Oct 30, 2022
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
An Generic HTTP Request Library For Swift

GRequest An HTTP request library written in Swift. ##Basic Usage Be simple, as it should be: Request("https://api.github.com/repos/lingoer/SwiftyJSON/

Ruoyu Fu 114 Oct 18, 2022
ServiceData is an HTTP networking library written in Swift which can download different types of data.

ServiceData Package Description : ServiceData is an HTTP networking library written in Swift which can download different types of data. Features List

Mubarak Alseif 0 Nov 11, 2021
An awesome Swift HTTP library to rapidly create communication layers with API endpoints

An awesome Swift HTTP library to rapidly create communication layers with API endpoints

Binary Birds 69 Nov 28, 2022
Minimalist HTTP request library via async / await

Making HTTP API requests in Swift using Foundation can be verbose and use a mix of types like URL, URLComponents and URLRequest to form a request and then handling all the encoding and decoding steps later

Nicholas Maccharoli 13 Nov 5, 2022