http

package
v0.9.266 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 136

Documentation

Overview

Package http defines the structure of request and response which used to access the BCE services as well as the http constant headers and and methods. And finally implement the `Execute` funct- ion to do the work.

Index

Constants

View Source
const (
	GET     = "GET"
	PUT     = "PUT"
	POST    = "POST"
	DELETE  = "DELETE"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
	PATCH   = "PATCH"
)

Constants of the supported HTTP methods for BCE

View Source
const (
	// Standard HTTP Headers
	AUTHORIZATION       = "Authorization"
	CACHE_CONTROL       = "Cache-Control"
	CONTENT_DISPOSITION = "Content-Disposition"
	CONTENT_ENCODING    = "Content-Encoding"
	CONTENT_LANGUAGE    = "Content-Language"
	CONTENT_LENGTH      = "Content-Length"
	CONTENT_MD5         = "Content-Md5"
	CONTENT_RANGE       = "Content-Range"
	CONTENT_TYPE        = "Content-Type"
	DATE                = "Date"
	ETAG                = "Etag"
	EXPIRES             = "Expires"
	HOST                = "Host"
	LAST_MODIFIED       = "Last-Modified"
	LOCATION            = "Location"
	RANGE               = "Range"
	SERVER              = "Server"
	TRANSFER_ENCODING   = "Transfer-Encoding"
	USER_AGENT          = "User-Agent"
	IF_MATCH            = "If-Match"
	IF_NONE_MATCH       = "If-None-Match"
	IF_MODIFIED_SINCE   = "If-Modified-Since"
	IF_UNMODIFIED_SINCE = "If-Unmodified-Since"

	// BCE Common HTTP Headers
	BCE_PREFIX               = "x-bce-"
	BCE_ACL                  = "x-bce-acl"
	BCE_GRANT_READ           = "x-bce-grant-read"
	BCE_GRANT_FULL_CONTROL   = "x-bce-grant-full-control"
	BCE_CONTENT_SHA256       = "x-bce-content-sha256"
	BCE_CONTENT_CRC32        = "x-bce-content-crc32"
	BCE_CONTENT_CRC32C       = "x-bce-content-crc32c"
	BCE_CONTENT_CRC32C_FLAG  = "x-bce-content-crc32c-flag"
	BCE_REQUEST_ID           = "x-bce-request-id"
	BCE_USER_METADATA_PREFIX = "x-bce-meta-"
	BCE_SECURITY_TOKEN       = "x-bce-security-token"
	BCE_DATE                 = "x-bce-date"
	BCE_TAG                  = "x-bce-tag-list"

	// BOS HTTP Headers
	BCE_COPY_METADATA_DIRECTIVE         = "x-bce-metadata-directive"
	BCE_COPY_TAGGING_DIRECTIVE          = "x-bce-tagging-directive"
	BCE_COPY_SOURCE                     = "x-bce-copy-source"
	BCE_COPY_SOURCE_IF_MATCH            = "x-bce-copy-source-if-match"
	BCE_COPY_SOURCE_IF_MODIFIED_SINCE   = "x-bce-copy-source-if-modified-since"
	BCE_COPY_SOURCE_IF_NONE_MATCH       = "x-bce-copy-source-if-none-match"
	BCE_COPY_SOURCE_IF_UNMODIFIED_SINCE = "x-bce-copy-source-if-unmodified-since"
	BCE_COPY_SOURCE_RANGE               = "x-bce-copy-source-range"
	BCE_DEBUG_ID                        = "x-bce-debug-id"
	BCE_OBJECT_TYPE                     = "x-bce-object-type"
	BCE_NEXT_APPEND_OFFSET              = "x-bce-next-append-offset"
	BCE_STORAGE_CLASS                   = "x-bce-storage-class"
	BCE_PROCESS                         = "x-bce-process"
	BCE_RESTORE_TIER                    = "x-bce-restore-tier"
	BCE_RESTORE_DAYS                    = "x-bce-restore-days"
	BCE_RESTORE                         = "x-bce-restore"
	BCE_FORBID_OVERWRITE                = "x-bce-forbid-overwrite"
	BCE_SYMLINK_TARGET                  = "x-bce-symlink-target"
	BCE_SYMLINK_BUCKET                  = "x-bce-symlink-bucket"
	BCE_TRAFFIC_LIMIT                   = "x-bce-traffic-limit"
	BCE_BUCKET_TYPE                     = "x-bce-bucket-type"
	BCE_OBJECT_TAGGING                  = "x-bce-tagging"
	BCE_FETCH_CALLBACK_ADDRESS          = "x-bce-callback-address"
	BCE_VERSION_ID                      = "x-bce-version-id"
	BCE_OBJECT_EXPIRES                  = "x-bce-object-expires"
	BCE_EXPIRATION_DATE                 = "x-bce-expiration-date"
	BCE_SERVER_SIDE_ENCRYPTION          = "x-bce-server-side-encryption"
	BCE_SERVER_SIDE_ENCRYPTION_KEY      = "x-bce-server-side-encryption-customer-key"
	BCE_SERVER_SIDE_ENCRYPTION_KEY_MD5  = "x-bce-server-side-encryption-customer-key-md5"
	BCE_SERVER_SIDE_ENCRYPTION_KEY_ID   = "x-bce-server-side-encryption-bos-kms-key-id"
	BCE_OBJECT_RETENTION_DATE           = "x-bce-object-rentention-date"
	BCE_TAGGING_COUNT                   = "x-bce-tagging-count"
	BCE_CONTENT_CRC64ECMA               = "x-bce-content-crc64ecma"
	//post field
	SUCCESS_ACTION_REDIRECT = "success-action-redirect"
	SUCCESS_ACTION_STATUS   = "success-action-status"
	//options header
	ORIGIN                           = "Origin"
	ACCESS_CONTROL_REQUEST_METHOD    = "Access-Control-Request-Method"
	ACCESS_CONTROL_REQUEST_HEADERS   = "Access-Control-Request-Headers"
	ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials"
	ACCESS_CONTROL_ALLOW_HEADERS     = "Access-Control-Allow-Headers"
	ACCESS_CONTROL_ALLOW_METHODS     = "Access-Control-Allow-Methods"
	ACCESS_CONTROL_ALLOW_ORIGIN      = "Access-Control-Allow-Origin"
	ACCESS_CONTROL_EXPOSE_HEADERS    = "Access-Control-Expose-Headers"
	ACCESS_CONTROL_MAX_AGE           = "Access-Control-Max-Age"
)

Constants of the HTTP headers for BCE

Variables

View Source
var DefaultClientConfig = ClientConfig{
	RedirectDisabled:      false,
	DisableKeepAlives:     false,
	DialTimeout:           &defaultDialTimeout,
	KeepAlive:             &defaultKeepAlive,
	TLSHandshakeTimeout:   &defaultTLSHandshakeTimeout,
	IdleConnectionTimeout: &defaultIdleConnTimeout,
	ResponseHeaderTimeout: &defaultResponseHeaderTimeout,
	HTTPClientTimeout:     &defaultHTTPClientTimeout,
}
View Source
var (
	NilHTTPClient = fmt.Errorf("custom HTTP Client is nil")
)

Functions

func InitClient added in v0.9.21

func InitClient(config ClientConfig)

func InitClientWithTimeout added in v0.9.235

func InitClientWithTimeout(config *ClientConfig)

func InitExclusiveHTTPClient added in v0.9.246

func InitExclusiveHTTPClient(config *ClientConfig) *http.Client

func InitWithSpecifiedClient added in v0.9.255

func InitWithSpecifiedClient(customHTTPClient *http.Client) error

func NewTransportCustom added in v0.9.235

func NewTransportCustom(config *ClientConfig) *http.Transport

func SetResponseHeaderTimeout added in v0.9.169

func SetResponseHeaderTimeout(t int)

Types

type ClientConfig added in v0.9.21

type ClientConfig struct {
	RedirectDisabled      bool
	DisableKeepAlives     bool
	NoVerifySSL           bool
	DialTimeout           *time.Duration
	KeepAlive             *time.Duration
	ReadTimeout           *time.Duration
	WriteTimeout          *time.Duration
	TLSHandshakeTimeout   *time.Duration
	IdleConnectionTimeout *time.Duration
	ResponseHeaderTimeout *time.Duration
	HTTPClientTimeout     *time.Duration
	PostRead              []func(n int, err error)
	PostWrite             []func(n int, err error)
}

func MergeWithDefaultConfig added in v0.9.235

func MergeWithDefaultConfig(cfgs ...*ClientConfig) *ClientConfig

func (*ClientConfig) Copy added in v0.9.235

func (cfg *ClientConfig) Copy(src *ClientConfig)

type Dialer added in v0.9.235

type Dialer struct {
	net.Dialer
	ReadTimeout  *time.Duration
	WriteTimeout *time.Duration
	// contains filtered or unexported fields
}

func NewDialer added in v0.9.235

func NewDialer(config *ClientConfig) *Dialer

func (*Dialer) Dial added in v0.9.235

func (d *Dialer) Dial(network, address string) (net.Conn, error)

func (*Dialer) DialContext added in v0.9.235

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type Request

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

Reauest stands for the general http request structure to make request to the BCE services.

func (*Request) Body

func (r *Request) Body() io.ReadCloser

func (*Request) Context added in v0.9.228

func (r *Request) Context() context.Context

func (*Request) Endpoint

func (r *Request) Endpoint() string

func (*Request) GenerateUrl

func (r *Request) GenerateUrl(addPort bool) string

func (*Request) HTTPClient added in v0.9.246

func (r *Request) HTTPClient() *http.Client

func (*Request) Header

func (r *Request) Header(key string) string

func (*Request) Headers

func (r *Request) Headers() map[string]string

func (*Request) Host

func (r *Request) Host() string

func (*Request) Length

func (r *Request) Length() int64

func (*Request) Method

func (r *Request) Method() string

func (*Request) Param

func (r *Request) Param(key string) string

func (*Request) Params

func (r *Request) Params() map[string]string

func (*Request) Port

func (r *Request) Port() int

func (*Request) Protocol

func (r *Request) Protocol() string

func (*Request) ProxyUrl

func (r *Request) ProxyUrl() string

func (*Request) QueryString

func (r *Request) QueryString() string

func (*Request) SetBody

func (r *Request) SetBody(stream io.ReadCloser)

func (*Request) SetContext added in v0.9.228

func (r *Request) SetContext(ctx context.Context)

func (*Request) SetEndpoint

func (r *Request) SetEndpoint(endpoint string)

func (*Request) SetHTTPClient added in v0.9.246

func (r *Request) SetHTTPClient(client *http.Client)

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string)

func (*Request) SetHeaders

func (r *Request) SetHeaders(headers map[string]string)

func (*Request) SetHost

func (r *Request) SetHost(host string)

func (*Request) SetLength

func (r *Request) SetLength(l int64)

func (*Request) SetMethod

func (r *Request) SetMethod(method string)

func (*Request) SetParam

func (r *Request) SetParam(key, value string)

func (*Request) SetParams

func (r *Request) SetParams(params map[string]string)

func (*Request) SetPort

func (r *Request) SetPort(port int)

func (*Request) SetProtocol

func (r *Request) SetProtocol(protocol string)

func (*Request) SetProxyUrl

func (r *Request) SetProxyUrl(url string)

func (*Request) SetTimeout

func (r *Request) SetTimeout(timeout int)

func (*Request) SetUri

func (r *Request) SetUri(uri string)

func (*Request) String

func (r *Request) String() string

func (*Request) Timeout

func (r *Request) Timeout() int

func (*Request) Uri

func (r *Request) Uri() string

type Response

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

Response defines the general http response structure for accessing the BCE services.

func Execute

func Execute(request *Request) (*Response, error)

Execute - do the http requset and get the response

PARAMS:

  • request: the http request instance to be sent

RETURNS:

  • response: the http response returned from the server
  • error: nil if ok otherwise the specific error

func (*Response) Body

func (r *Response) Body() io.ReadCloser

func (*Response) ContentLength

func (r *Response) ContentLength() int64

func (*Response) ElapsedTime

func (r *Response) ElapsedTime() time.Duration

func (*Response) GetHeader

func (r *Response) GetHeader(name string) string

func (*Response) GetHeaders

func (r *Response) GetHeaders() map[string]string

func (*Response) HttpResponse

func (r *Response) HttpResponse() *http.Response

func (*Response) Protocol

func (r *Response) Protocol() string

func (*Response) SetHttpResponse

func (r *Response) SetHttpResponse(response *http.Response)

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) StatusText

func (r *Response) StatusText() string

Jump to

Keyboard shortcuts

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