From d8a4dae6ad9672285dc007e7c52c63026278d00a Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 12 Dec 2024 21:12:26 +0700 Subject: lib/http: add method to return default HTTP Transport in Client The returned [http.Transport] is created after the Client instantiated. Their value can be customized by user when needed, which should affect the Transport inside the Client. --- lib/http/client.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/http/client.go b/lib/http/client.go index d5045fee..2dad2159 100644 --- a/lib/http/client.go +++ b/lib/http/client.go @@ -1,6 +1,6 @@ -// Copyright 2020, Shulhan . All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2020 M. Shulhan +// +// SPDX-License-Identifier: BSD-3-Clause package http @@ -450,6 +450,13 @@ func (client *Client) PutJSON(req ClientRequest) (res *ClientResponse, err error return client.doRequest(req) } +// Transport return the [http.Transport] that Client use in the +// RoundTripper. +func (client *Client) Transport() (transport *http.Transport) { + transport, _ = client.Client.Transport.(*http.Transport) + return transport +} + func (client *Client) doRequest(req ClientRequest) (res *ClientResponse, err error) { req.Path = path.Join(`/`, req.Path) -- cgit v1.3