001package io.freefair.spring.okhttp.client;
002
003import okhttp3.OkHttpClient;
004import org.springframework.http.HttpMethod;
005import org.springframework.http.client.ClientHttpRequest;
006import org.springframework.http.client.ClientHttpRequestFactory;
007import org.springframework.lang.NonNull;
008
009import java.net.URI;
010
011/**
012 * OkHttp based {@link ClientHttpRequestFactory} implementation.
013 * <p>
014 * Serves as replacement for the deprecated {@link org.springframework.http.client.OkHttp3ClientHttpRequestFactory}.
015 *
016 * @author Lars Grefer
017 */
018public record OkHttpClientRequestFactory(@NonNull OkHttpClient okHttpClient) implements ClientHttpRequestFactory {
019
020    @Override
021    public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) {
022        return new OkHttpClientRequest(okHttpClient, uri, httpMethod);
023    }
024
025}