我试图让服务器推送在iOS 10上工作,我正在完成Akamai /2演示。
下面是我测试服务器推送的尝试。
@interface ViewController () <NSURLSessionTaskDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSString *displayArtUrl;
for(int i=0; i<378; i++) {
displayArtUrl = [NSString stringWithFormat:@"https://http2.akamai.com/demo/tile-%ld.png", (long)i];
NSURL *url = [NSURL URLWithString:displayArtUrl];
NSURLSessionDataTask *downloadTask = [defaultSession
dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
}];
[downloadTask resume];
}
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didFinishCollectingMetrics:(NSURLSessionTaskMetrics *)metrics {
NSArray *fetchTypes = @[ @"Unknown", @"Network Load", @"Server Push", @"Local Cache" ];
for(NSURLSessionTaskTransactionMetrics *transactionMetrics in [metrics transactionMetrics]) {
NSLog(@"protocol[%@] reuse[%d] fetch:%@ - %@", [transactionMetrics networkProtocolName], [transactionMetrics isReusedConnection], fetchTypes[[transactionMetrics resourceFetchType]], [[transactionMetrics request] URL]);
if([transactionMetrics resourceFetchType] == NSURLSessionTaskMetricsResourceFetchTypeServerPush) {
NSLog(@"Asset was server pushed");
}
}
}
@end不幸的是,日志显示,当我有时期望提取类型是时,它总是类型。服务器显然支持它,如web演示所示。
...
2016-11-22 19:27:37.596205 HttpServerPush[2356:735927] protocol[h2] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-4.png
2016-11-22 19:27:37.596960 HttpServerPush[2356:735927] protocol[h2] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-5.png
2016-11-22 19:27:37.597877 HttpServerPush[2356:735927] protocol[h2] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-6.png
2016-11-22 19:27:37.603988 HttpServerPush[2356:735927] protocol[h2] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-1.png
2016-11-22 19:27:37.976911 HttpServerPush[2356:735927] protocol[h2] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-7.png
....有没有人在iOS 10上成功地使用HTTP/2服务器?在申请资产的方式中是否缺少了什么?
FYI,Charles似乎在这个场景中遇到了麻烦。启用它将导致iOS 10完全停止使用HTTP/2。
...
2016-11-22 19:55:15.763 HttpServerPush[59822:1612935] protocol[http/1.1] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-8.png
2016-11-22 19:55:15.766 HttpServerPush[59822:1612935] protocol[http/1.1] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-11.png
2016-11-22 19:55:15.769 HttpServerPush[59822:1612935] protocol[http/1.1] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-9.png
2016-11-22 19:55:15.771 HttpServerPush[59822:1612935] protocol[http/1.1] reuse[1] fetch:Network Load - https://http2.akamai.com/demo/tile-12.png
...发布于 2016-11-23 05:29:09
据我所知,Akamai演示页面目前没有推送任何资源。当服务器向客户端发送PUSH_PROMISE帧时,就会发生推送。nghttp (可通过brew在Mac:brew install nghttp2上安装)可用于显示服务器发送的帧:
$ nghttp -nv 'https://http2.akamai.com/demo' | grep 'PUSH_PROMISE'
$另一方面,https://h2o.examp1e.net/ ( H2O HTTP服务器的主页)确实推送资源:
$ nghttp -nv 'https://h2o.examp1e.net' | grep 'PUSH_PROMISE'
[ 0.587] recv PUSH_PROMISE frame <length=59, flags=0x04, stream_id=13>
[ 0.587] recv PUSH_PROMISE frame <length=33, flags=0x04, stream_id=13>
[ 0.588] recv PUSH_PROMISE frame <length=35, flags=0x04, stream_id=13>
[ 0.588] recv PUSH_PROMISE frame <length=24, flags=0x04, stream_id=13>
[ 0.588] recv PUSH_PROMISE frame <length=28, flags=0x04, stream_id=13>
$发布于 2016-11-23 05:57:36
HTTP/2 Push在Safari中被广泛认为是被破坏的。不要认为这些信息是最新的,但是上一次我检查浏览器将接受并有时使用推送资源,而其他时候则不会。
原始答案
我正要回答您,iOS中不支持HTTP/2 Push,但随后我快速查看了我们的页面:
并等待连接状态出现在右上角。iOS 10支持HTTP/2推送!
https://stackoverflow.com/questions/40755758
复制相似问题