首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 10中的HTTP/2服务器推送

iOS 10中的HTTP/2服务器推送
EN

Stack Overflow用户
提问于 2016-11-23 03:57:15
回答 2查看 1.9K关注 0票数 3

我试图让服务器推送在iOS 10上工作,我正在完成Akamai /2演示。

https://http2.akamai.com/demo

下面是我测试服务器推送的尝试。

代码语言:javascript
复制
@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演示所示。

代码语言:javascript
复制
...
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。

代码语言:javascript
复制
...
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
...
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-23 05:29:09

据我所知,Akamai演示页面目前没有推送任何资源。当服务器向客户端发送PUSH_PROMISE帧时,就会发生推送。nghttp (可通过brew在Mac:brew install nghttp2上安装)可用于显示服务器发送的帧:

代码语言:javascript
复制
$ nghttp -nv 'https://http2.akamai.com/demo' | grep 'PUSH_PROMISE'
$

另一方面,https://h2o.examp1e.net/ ( H2O HTTP服务器的主页)确实推送资源:

代码语言:javascript
复制
$ 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>
$
票数 2
EN

Stack Overflow用户

发布于 2016-11-23 05:57:36

HTTP/2 Push在Safari中被广泛认为是被破坏的。不要认为这些信息是最新的,但是上一次我检查浏览器将接受并有时使用推送资源,而其他时候则不会。

原始答案

我正要回答您,iOS中不支持HTTP/2 Push,但随后我快速查看了我们的页面:

https://www.shimmercat.com

并等待连接状态出现在右上角。iOS 10支持HTTP/2推送!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40755758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档