1

我想从同一个 HTTP 服务器下载很多图像,所以我想在同一个 TCP 连接上完成所有这些工作。我所能找到的只是NSMutableURLRequest允许我启用流水线(HTTPShouldUsePipelining),但我不明白当我启用流水线时它如何知道要一起发送哪些请求。

我试过了,根据 Wireshark 的说法,这两个请求和响应位于不同的 TCP 流上,所以看起来它实际上并不是在流水线化请求:

    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")
    }

我还在我自己的本地 Nginx 服务器上进行了尝试,以防万一 Strabo.com 不支持流水线。

此外,SDWebImageDownloader我注意到,不知何故使用了 HTTP 流水线。我看到多个请求在同一个 TCP 流中发送。但是,它不会将所有这些都发送到同一个流上,我想这样做,所以我一直在尝试实现一个自定义下载器。

4

0 回答 0