NSMutableURLRequest pipelining confusion

165 views Asked by At

I want to download a lot of images from the same HTTP server, so I want to do all of that on the same TCP connection. All I can find is that NSMutableURLRequest allows me to enable pipelining (HTTPShouldUsePipelining), but I don't understand how it knows which requests to send together when I enable pipelining.

I tried this, and according to Wireshark, the two requests and responses are on separate TCP streams, so it doesn't seem like it's actually pipelining the requests:

    var request0 = NSMutableURLRequest(URL: NSURL(string: "http://strabo.com/gallery/albums/wallpaper/foo_wallpaper.sized.jpg")!)
    var request1 = NSMutableURLRequest(URL: NSURL(string: "http://strabo.com/gallery/albums/wallpaper/foo_wallpaper.sized.jpg")!)
    request0.HTTPShouldUsePipelining = true
    request1.HTTPShouldUsePipelining = true
    var queue = NSOperationQueue()
    NSURLConnection.sendAsynchronousRequest(request0, queue: queue) { (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
        println("response0")
    }
    NSURLConnection.sendAsynchronousRequest(request1, queue: queue) { (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
        println("response1")
    }

I also tried on my own local Nginx server just in case Strabo.com doesn't support pipelining.

Also, SDWebImageDownloader somehow uses HTTP pipelining, I've noticed. I see that multiple requests are sent within the same TCP stream. However, it doesn't send all of them on the same stream, and I want to do that, so I've been trying to implement a custom downloader.

0

There are 0 answers