HTTP GET JSON with cancellation-based timeout

C#
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;

static async Task<T?> GetJsonAsync<T>(string url, int timeoutMs = 5000)
{
    using var cts = new CancellationTokenSource(timeoutMs);
    using var http = new HttpClient { Timeout = Timeout.InfiniteTimeSpan };
    try
    {
        using var response = await http.GetAsync(url, cts.Token);
        response.EnsureSuccessStatusCode();
        return await response.Content.ReadFromJsonAsync<T>(cancellationToken: cts.Token);
    }
    catch (OperationCanceledException) when (cts.IsCancellationRequested)
    {
        throw new TimeoutException($"GET {url} timed out after {timeoutMs} ms");
    }
}