httpclient

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentDownloadFlags

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

type ConnectHandler

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

type DownloadFileDetails

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

type ErrorHandler

type ErrorHandler func([]byte) error

type HttpClient

type HttpClient struct {
	Client *http.Client
}

func NewDefaultHttpClient

func NewDefaultHttpClient() *HttpClient

func NewHttpClient

func NewHttpClient(client *http.Client) *HttpClient

func (*HttpClient) DownloadFile

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

func (*HttpClient) DownloadFileConcurrently

func (jc *HttpClient) DownloadFileConcurrently(flags ConcurrentDownloadFlags, logMsgPrefix string, httpClientsDetails httputils.HttpClientDetails) error

func (*HttpClient) DownloadFileNoRedirect

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

func (*HttpClient) GetRemoteFileDetails

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

func (*HttpClient) IsAcceptRanges

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

func (*HttpClient) ReadRemoteFile

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

Read remote file, The caller is responsible to close the io.ReaderCloser

func (*HttpClient) Send

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

func (*HttpClient) SendDelete

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

func (*HttpClient) SendGet

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

func (*HttpClient) SendHead

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

func (*HttpClient) SendPatch

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

func (*HttpClient) SendPost

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

func (*HttpClient) SendPut

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

func (*HttpClient) Stream

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

func (*HttpClient) UploadFile

func (jc *HttpClient) UploadFile(localPath, url string, httpClientsDetails httputils.HttpClientDetails, retries int) (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