# HTTP/3 support for URLSession

HTTP/3 uses [QUIC](https://en.wikipedia.org/wiki/QUIC), a [multiplexed](https://en.wikipedia.org/wiki/Multiplexing) transport protocol built on [UDP](https://en.wikipedia.org/wiki/User_Datagram_Protocol). Do you need to change anything for your iOS apps when using URLSession?

The quick answer is: No, <mark>HTTP3 support is enabled by default in URLSession.</mark>

WWDC 2021 session [Accelerate networking with HTTP/3 and QUIC](https://developer.apple.com/videos/play/wwdc2021/10094/?time=294) gives you the following statement:

> If you're using URLSession, you don't need to change your app since iOS 15 and macOS Monterey ship with HTTP/3 enabled by default. Once you enable HTTP/3 on your server, you're good to go.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1670425013270/d2bx61_2h.png align="center")

Apple's Technote [TN3102: HTTP/3 in your app](https://developer.apple.com/documentation/technotes/tn3102-http3-in-your-app) does not give you such a simple answer, but it provides sample code and instructions on how you can verify that HTTP/3 was actually used.

The Technote also goes into detail on how URLSession may discover to use HTTP/3.

Service discovery for `HTTP/3` is performed in one of the following ways:

*   The recommended approach is to configure your DNS server to advertise the HTTPS resource record for `alpn="h3,h2"`.
    
*   Alternatively, configure your server to respond back with the `Alt-Svc` header that advertises `HTTP/3`. For example, `Alt-Srv: h3=":443"; ma=2592000`.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1670425026000/4O38v0muF.png align="center")

URLSession won't use HTTP/3 unless it was advertised.

Hence you might observe that the very first connection does not use HTTP/3 and only for subsequent connections.

To attempt to use `HTTP/3` on the first transaction, you can set the [assumesHTTP3Capable](https://developer.apple.com/documentation/foundation/urlrequest/3738175-assumeshttp3capable) property on the [URLRequest](https://developer.apple.com/documentation/foundation/urlrequest) before passing it to a data task in [URLSession](https://developer.apple.com/documentation/foundation/urlsession).

```swift
//var request: URLRequest = ...
request.assumesHTTP3Capable = true
```

Networks may still block HTTP/3, or your server may not support HTTP/3. In that case, Apple will fall back to HTTP/2.
