httpclient

package
v1.40.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 25 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDialTimeout = 30 * time.Second

Functions

func ClientBuilder

func ClientBuilder() *httpClientBuilder

func IsApiKey added in v1.26.1

func IsApiKey(key string) bool

func SetUberTraceIdToken added in v1.40.2

func SetUberTraceIdToken(traceIdToken string)

Generate an Uber Trace ID token that will be attached to every request. Format of the header: {trace-id}:{span-id}:{parent-span-id}:{flags} We set the trace-id and span-id to the same value, and the rest to 0.

Types

type ConcurrentDownloadFlags

type ConcurrentDownloadFlags struct {
	FileName                string
	DownloadPath            string
	RelativePath            string
	LocalFileName           string
	LocalPath               string
	ExpectedSha1            string
	FileSize                int64
	SplitCount              int
	Explode                 bool
	BypassArchiveInspection bool
	SkipChecksum            bool
}

type ConnectHandler

type ConnectHandler func() (*http.Response, error)

type DownloadFileDetails

type DownloadFileDetails struct {
	FileName      string `json:"FileName,omitempty"`
	DownloadPath  string `json:"DownloadPath,omitempty"`
	RelativePath  string `json:"RelativePath,omitempty"`
	LocalPath     string `json:"LocalPath,omitempty"`
	LocalFileName string `json:"LocalFileName,omitempty"`
	ExpectedSha1  string `json:"ExpectedSha1,omitempty"`
	Size          int64  `json:"Size,omitempty"`
	SkipChecksum  bool   `json:"SkipChecksum,omitempty"`
}

type ErrorHandler

type ErrorHandler func([]byte) error

type HttpClient

type HttpClient struct {
	// contains filtered or unexported fields
}

func (*HttpClient) DownloadFile

func (jc *HttpClient) DownloadFile(downloadFileDetails *DownloadFileDetails, logMsgPrefix string,
	httpClientsDetails httputils.HttpClientDetails, isExplode, bypassArchiveInspection bool) (*http.Response, error)

Bulk downloads a file.

func (*HttpClient) DownloadFileConcurrently

func (jc *HttpClient) DownloadFileConcurrently(flags ConcurrentDownloadFlags, logMsgPrefix string,
	httpClientsDetails httputils.HttpClientDetails, progress ioutils.ProgressMgr) (resp *http.Response, err error)

Downloads a file by chunks, concurrently. If successful, returns the resp of the last chunk, which will have resp.StatusCode = http.StatusPartialContent Otherwise: if an error occurred - returns the error with resp=nil, else - err=nil and the resp of the first chunk that received statusCode!=http.StatusPartialContent The caller is responsible to check the resp.StatusCode. You may implement the log.Progress interface, or pass nil to run without progress display.

func (*HttpClient) DownloadFileNoRedirect

func (jc *HttpClient) DownloadFileNoRedirect(downloadPath, localPath, fileName string, httpClientsDetails httputils.HttpClientDetails) (*http.Response, string, error)

func (*HttpClient) DownloadFileWithProgress

func (jc *HttpClient) DownloadFileWithProgress(downloadFileDetails *DownloadFileDetails, logMsgPrefix string,
	httpClientsDetails httputils.HttpClientDetails, isExplode, isBypassArchiveInspection bool, progress ioutils.ProgressMgr) (*http.Response, error)

Bulk downloads a file. You may implement the log.Progress interface, or pass nil to run without progress display.

func (*HttpClient) GetClient added in v1.34.4

func (jc *HttpClient) GetClient() *http.Client

func (*HttpClient) GetRemoteFileDetails

func (jc *HttpClient) GetRemoteFileDetails(downloadUrl string, httpClientsDetails httputils.HttpClientDetails) (*fileutils.FileDetails, *http.Response, error)

The caller is responsible to check that resp.StatusCode is http.StatusOK

func (*HttpClient) GetRetries added in v0.25.0

func (jc *HttpClient) GetRetries() int

func (*HttpClient) GetRetryWaitTime added in v1.7.0

func (jc *HttpClient) GetRetryWaitTime() int

func (*HttpClient) IsAcceptRanges

func (jc *HttpClient) IsAcceptRanges(downloadUrl string, httpClientsDetails httputils.HttpClientDetails) (bool, *http.Response, error)

The caller is responsible to check if resp.StatusCode is StatusOK before relying on the bool value

func (*HttpClient) ReadRemoteFile

func (jc *HttpClient) ReadRemoteFile(downloadPath string, httpClientsDetails httputils.HttpClientDetails) (io.ReadCloser, *http.Response, error)

Read remote file, The caller is responsible to check if resp.StatusCode is StatusOK before reading, and to close io.ReadCloser after done reading.

func (*HttpClient) Send

func (jc *HttpClient) Send(method, url string, content []byte, followRedirect, closeBody bool, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, respBody []byte, redirectUrl string, err error)

func (*HttpClient) SendDelete

func (jc *HttpClient) SendDelete(url string, content []byte, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, body []byte, err error)

func (*HttpClient) SendGet

func (jc *HttpClient) SendGet(url string, followRedirect bool, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, respBody []byte, redirectUrl string, err error)

func (*HttpClient) SendHead

func (jc *HttpClient) SendHead(url string, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, body []byte, err error)

func (*HttpClient) SendPatch

func (jc *HttpClient) SendPatch(url string, content []byte, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, body []byte, err error)

func (*HttpClient) SendPost

func (jc *HttpClient) SendPost(url string, content []byte, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, body []byte, err error)

func (*HttpClient) SendPostLeaveBodyOpen

func (jc *HttpClient) SendPostLeaveBodyOpen(url string, content []byte, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, err error)

func (*HttpClient) SendPut

func (jc *HttpClient) SendPut(url string, content []byte, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (resp *http.Response, body []byte, err error)

func (*HttpClient) Stream

func (jc *HttpClient) Stream(url string, httpClientsDetails httputils.HttpClientDetails, logMsgPrefix string) (*http.Response, []byte, string, error)

func (*HttpClient) UploadFile

func (jc *HttpClient) UploadFile(localPath, url, logMsgPrefix string, httpClientsDetails httputils.HttpClientDetails,
	progress ioutils.ProgressMgr) (resp *http.Response, body []byte, err error)

You may implement the log.Progress interface, or pass nil to run without progress display.

func (*HttpClient) UploadFileFromReader added in v0.20.1

func (jc *HttpClient) UploadFileFromReader(reader io.Reader, url string, httpClientsDetails httputils.HttpClientDetails,
	size int64) (resp *http.Response, body []byte, err error)

type RetryableConnection

type RetryableConnection struct {
	// ReadTimeout, if read timeout time passes without any data received from the server the connection will be closed.
	ReadTimeout time.Duration

	// RetriesNum represents the number of retries following a lost connection, -1 for unlimited
	RetriesNum int

	// StableConnectionWindow sets the duration of a stable connection after which the RetriesNum is reset.
	// If 0 RetriesNum is never reset.
	// It is recommended to use longer time than ReadTimeout.
	StableConnectionWindow time.Duration

	// SleepBetweenRetries sleep time between two retires.
	SleepBetweenRetries time.Duration

	// ConnectHandler will be called for connection retry, make sure response body is not closed.
	ConnectHandler ConnectHandler

	// ErrorHandler will be called after successful connection for content errors checks.
	ErrorHandler ErrorHandler
}

func (*RetryableConnection) Do

func (rt *RetryableConnection) Do() ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL