iOS HTTP3

作者: tom__zhu | 来源:发表于2021-11-18 16:44 被阅读0次

HTTP3是iOS15中一个全新特性#,这个特性也需要你们后端服务支持,接下来讲一下如何在你的APP中使用这个能力

客户端

  • 需要真机才能支持HTTP3。
  • 开发者模式中的HTTP/3选项对结果有一些影响,但实测发现Xcode联调才有影响。
  • 如果请求的protocol一直是h2,那么断开Xcode联调,改用console查看输出的protocol,应该会不一样。
  • HTTP协议可能会是h3,但有些情况下会返回h2或是h1.1,这是竞速情况下的正常现象,通常情况会是先h2然后再显示h3。这种特性是由<alt-svc>实现#
  • 另外charles不支持http3,所以连接代理无法发出http3请求,至于charles后续版本是否支持可以关注(Charles Version History

服务端

NOTE: Servers that support HTTP3 should be based on Draft 29 or later.

使用姿势

  1. Install iOS 15.0 beta on a test device (HTTP/3 is not supported in the simulator).
  2. In Settings > Developer, under the Networking group, enable HTTP/3.
  3. Using Xcode 13.0 beta, create a new project from the iOS > App template. Set the Interface popup to Storyboard and the Language popup to Swift.
  4. try using the assumesHTTP3Capable property on the URLRequest being used to execute the dataTask in URLSession
import UIKit

class ViewController: UIViewController, URLSessionDataDelegate {

    private var session: URLSession!

    @IBAction
    private func testAction(_ sender: Any) {
        if self.session == nil {
            let config = URLSessionConfiguration.default
            config.requestCachePolicy = .reloadIgnoringLocalCacheData
            self.session = URLSession(configuration: config, delegate: self, delegateQueue: .main)
        }

        let urlStr = "<# Your H3 URL Here #>"
        let url = URL(string: urlStr)!
        var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 60.0)
        request.assumesHTTP3Capable = true
        print("task will start, url: \\(url.absoluteString)")
        self.session.dataTask(with: request) { (data, response, error) in
            if let error = error as NSError? {
                print("task transport error \\(error.domain) / \\(error.code)")
                return
            }
            let response = response as! HTTPURLResponse
            let data = data!
            print("task finished with status \\(response.statusCode), bytes \\(data.count)")
        }.resume()
    }

    func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
        let protocols = metrics.transactionMetrics.map { $0.networkProtocolName ?? "-" }
        print("protocols:", protocols)
    }
}

HTTP/3 test servers

URL Alt-Svc Implemenation
quic.aiortc.org pgjones.dev yes aioquic
cloudflare-quic.com quic.tech yes Cloudflare Quiche
facebook.com fb.mvfst.net no mvfst
quic.rocks yes Google quiche
f5quic.com no F5
www.litespeedtech.com yes lsquic
nghttp2.org no ngtcp2
test.privateoctopus.com no picoquic
h2o.examp1e.net yes h2o/quicly
quic.westus.cloudapp.azure.com yes msquic
docs.trafficserver.apache.org yes Apache Traffic Server

参考

HTTP/3 in your App
Who is ready for HTTP/3?

相关文章

  • iOS HTTP3

    HTTP3是iOS15中一个全新特性#[https://developer.apple.com/forums/th...

  • HTTP3过去现在和未来(译)

    在去年的HTTP3"生日周"期间,我们Cloudflare宣布了对Web的新标准QUIC和HTTP3(或当时称为"...

  • HTTP协议-HTTP3

    序言 上节提到HTTP3通过更加底层的传输层的优化来提升效率,究竟如何,让我们一起看一下。 HTTP3的优化 通过...

  • 网络请求库-Okhttp3

    0.参考: 官网: okhttp-Git地址 okio-Git地址 Ok http3的官网 文档: 1 2 3 3...

  • QUIC/HTTP3 协议简析

    从 HTTP 的进化历史讲起,细说使用协议的变迁,了解原因发现问题,解码 QUIC 在 HTTP3 中的支撑作用,...

  • Https相关知识

    参考资料整理了Https相关的东西,还没有涉及Http2,Http3。之后会继续学习补充。从https的作用、证书...

  • 网络编程懒人入门(十二):快速读懂Http/3协议,一篇就够!

    本文中文译文由作者“ably.io”发布于公众号“高可用架构”,译文原题:《深入解读HTTP3的原理及应用》、英文...

  • QUIC不是TCP的替代品

    QUIC取代了TCP成为HTTP3的基础传输协议,不是因为QUIC能够取代TCP的所有应用场景,而是因为QUIC更...

  • http3/quic环境搭建

    1,确保系统为centos,yum在线安装nginx-quic命令如下 2,配置nginx.conf 重启ngin...

  • 那些年,我们一起追的HTTP协议……

    最近刷公众号突然刷到了HTTP3的消息下一代HTTP底层协议将弃用TCP协议 改用QUIC技术。想起前几天才和人家...

网友评论

      本文标题:iOS HTTP3

      本文链接:https://www.haomeiwen.com/subject/hntjtrtx.html