http

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LastModified       = "Last-Modified"
	Date               = "Date"
	ETag               = "ETag"
	ContentType        = "Content-Type"
	ContentMD5         = "Content-Md5"
	ContentEncoding    = "Content-Encoding"
	Expires            = "Expires"
	ContentLength      = "Content-Length"
	ContentLanguage    = "Content-Language"
	ContentRange       = "Content-Range"
	Connection         = "Connection"
	AcceptRanges       = "Accept-Ranges"
	AmzBucketRegion    = "X-Amz-Bucket-Region"
	ServerInfo         = "Server"
	RetryAfter         = "Retry-After"
	Location           = "Location"
	CacheControl       = "Cache-Control"
	ContentDisposition = "Content-Disposition"
	Authorization      = "Authorization"
	Action             = "Action"
	Range              = "Range"
)

Standard S3 HTTP response constants

View Source
const (
	XCache       = "X-Cache"
	XCacheLookup = "X-Cache-Lookup"
)

Non standard S3 HTTP response constants

View Source
const (
	IfModifiedSince   = "If-Modified-Since"
	IfUnmodifiedSince = "If-Unmodified-Since"
	IfMatch           = "If-Match"
	IfNoneMatch       = "If-None-Match"

	// S3 storage class
	AmzStorageClass = "x-amz-storage-class"

	// S3 object version ID
	AmzVersionID    = "x-amz-version-id"
	AmzDeleteMarker = "x-amz-delete-marker"

	// S3 object tagging
	AmzObjectTagging = "X-Amz-Tagging"
	AmzTagCount      = "x-amz-tagging-count"
	AmzTagDirective  = "X-Amz-Tagging-Directive"

	// S3 transition restore
	AmzRestore            = "x-amz-restore"
	AmzRestoreExpiryDays  = "X-Amz-Restore-Expiry-Days"
	AmzRestoreRequestDate = "X-Amz-Restore-Request-Date"
	AmzRestoreOutputPath  = "x-amz-restore-output-path"

	// S3 extensions
	AmzCopySourceIfModifiedSince   = "x-amz-copy-source-if-modified-since"
	AmzCopySourceIfUnmodifiedSince = "x-amz-copy-source-if-unmodified-since"

	AmzCopySourceIfNoneMatch = "x-amz-copy-source-if-none-match"
	AmzCopySourceIfMatch     = "x-amz-copy-source-if-match"

	AmzCopySource                 = "X-Amz-Copy-Source"
	AmzCopySourceVersionID        = "X-Amz-Copy-Source-Version-Id"
	AmzCopySourceRange            = "X-Amz-Copy-Source-Range"
	AmzMetadataDirective          = "X-Amz-Metadata-Directive"
	AmzObjectLockMode             = "X-Amz-Object-Lock-Mode"
	AmzObjectLockRetainUntilDate  = "X-Amz-Object-Lock-Retain-Until-Date"
	AmzObjectLockLegalHold        = "X-Amz-Object-Lock-Legal-Hold"
	AmzObjectLockBypassGovernance = "X-Amz-Bypass-Governance-Retention"
	AmzBucketReplicationStatus    = "X-Amz-Replication-Status"

	// AmzSnowballExtract will trigger unpacking of an archive content
	AmzSnowballExtract = "X-Amz-Meta-Snowball-Auto-Extract"
	// MinIOSnowballIgnoreDirs will skip creating empty directory objects.
	MinIOSnowballIgnoreDirs = "X-Amz-Meta-Minio-Snowball-Ignore-Dirs"
	// MinIOSnowballIgnoreErrors will ignore recoverable errors, typically single files failing to upload.
	// An error will be printed to console instead.
	MinIOSnowballIgnoreErrors = "X-Amz-Meta-Minio-Snowball-Ignore-Errors"
	// MinIOSnowballPrefix will apply this prefix (plus / at end) to all extracted objects
	MinIOSnowballPrefix = "X-Amz-Meta-Minio-Snowball-Prefix"

	// Object lock enabled
	AmzObjectLockEnabled = "x-amz-bucket-object-lock-enabled"

	// Multipart parts count
	AmzMpPartsCount = "x-amz-mp-parts-count"

	// Object date/time of expiration
	AmzExpiration = "x-amz-expiration"

	// Dummy putBucketACL
	AmzACL = "x-amz-acl"

	// Signature V4 related contants.
	AmzContentSha256        = "X-Amz-Content-Sha256"
	AmzDate                 = "X-Amz-Date"
	AmzAlgorithm            = "X-Amz-Algorithm"
	AmzExpires              = "X-Amz-Expires"
	AmzSignedHeaders        = "X-Amz-SignedHeaders"
	AmzSignature            = "X-Amz-Signature"
	AmzCredential           = "X-Amz-Credential"
	AmzSecurityToken        = "X-Amz-Security-Token"
	AmzDecodedContentLength = "X-Amz-Decoded-Content-Length"
	AmzTrailer              = "X-Amz-Trailer"

	AmzMetaUnencryptedContentLength = "X-Amz-Meta-X-Amz-Unencrypted-Content-Length"
	AmzMetaUnencryptedContentMD5    = "X-Amz-Meta-X-Amz-Unencrypted-Content-Md5"

	// AWS server-side encryption headers for SSE-S3, SSE-KMS and SSE-C.
	AmzServerSideEncryption                      = "X-Amz-Server-Side-Encryption"
	AmzServerSideEncryptionKmsID                 = AmzServerSideEncryption + "-Aws-Kms-Key-Id"
	AmzServerSideEncryptionKmsContext            = AmzServerSideEncryption + "-Context"
	AmzServerSideEncryptionCustomerAlgorithm     = AmzServerSideEncryption + "-Customer-Algorithm"
	AmzServerSideEncryptionCustomerKey           = AmzServerSideEncryption + "-Customer-Key"
	AmzServerSideEncryptionCustomerKeyMD5        = AmzServerSideEncryption + "-Customer-Key-Md5"
	AmzServerSideEncryptionCopyCustomerAlgorithm = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Algorithm"
	AmzServerSideEncryptionCopyCustomerKey       = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key"
	AmzServerSideEncryptionCopyCustomerKeyMD5    = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key-Md5"

	AmzEncryptionAES = "AES256"
	AmzEncryptionKMS = "aws:kms"

	// Signature v2 related constants
	AmzSignatureV2 = "Signature"
	AmzAccessKeyID = "AWSAccessKeyId"

	// Response request id.
	AmzRequestID     = "x-amz-request-id"
	AmzRequestHostID = "x-amz-id-2"

	// Deployment id.
	MinioDeploymentID = "x-minio-deployment-id"

	// Peer call
	MinIOPeerCall = "x-minio-from-peer"

	// Server-Status
	MinIOServerStatus = "x-minio-server-status"

	// Content Checksums
	AmzChecksumAlgo   = "x-amz-checksum-algorithm"
	AmzChecksumCRC32  = "x-amz-checksum-crc32"
	AmzChecksumCRC32C = "x-amz-checksum-crc32c"
	AmzChecksumSHA1   = "x-amz-checksum-sha1"
	AmzChecksumSHA256 = "x-amz-checksum-sha256"
	AmzChecksumMode   = "x-amz-checksum-mode"

	// Delete special flag to force delete a bucket or a prefix
	MinIOForceDelete = "x-minio-force-delete"

	// Create special flag to force create a bucket
	MinIOForceCreate = "x-minio-force-create"

	// Header indicates if the mtime should be preserved by client
	MinIOSourceMTime = "x-minio-source-mtime"

	// Header indicates if the etag should be preserved by client
	MinIOSourceETag = "x-minio-source-etag"

	// Writes expected write quorum
	MinIOWriteQuorum = "x-minio-write-quorum"

	// Indicates if we are using default storage class and there was problem loading config
	// if this header is set to "true"
	MinIOStorageClassDefaults = "x-minio-storage-class-defaults"

	// Reports number of drives currently healing
	MinIOHealingDrives = "x-minio-healing-drives"

	// Header indicates if the delete marker should be preserved by client
	MinIOSourceDeleteMarker = "x-minio-source-deletemarker"

	// Header indicates if the delete marker version needs to be purged.
	MinIOSourceDeleteMarkerDelete = "x-minio-source-deletemarker-delete"

	// Header indicates permanent delete replication status.
	MinIODeleteReplicationStatus = "X-Minio-Replication-Delete-Status"
	// Header indicates delete-marker replication status.
	MinIODeleteMarkerReplicationStatus = "X-Minio-Replication-DeleteMarker-Status"
	// Header indicates if its a GET/HEAD proxy request for active-active replication
	MinIOSourceProxyRequest = "X-Minio-Source-Proxy-Request"
	// Header indicates that this request is a replication request to create a REPLICA
	MinIOSourceReplicationRequest = "X-Minio-Source-Replication-Request"
	// Header checks replication permissions without actually completing replication
	MinIOSourceReplicationCheck = "X-Minio-Source-Replication-Check"
	// Header indicates replication reset status.
	MinIOReplicationResetStatus = "X-Minio-Replication-Reset-Status"
	// Header indicating target cluster can receive delete marker replication requests because object has been replicated
	MinIOTargetReplicationReady = "X-Minio-Replication-Ready"
	// Header asking if cluster can receive delete marker replication request now.
	MinIOCheckDMReplicationReady = "X-Minio-Check-Replication-Ready"
	// Header indiicates last tag update time on source
	MinIOSourceTaggingTimestamp = "X-Minio-Source-Replication-Tagging-Timestamp"
	// Header indiicates last rtention update time on source
	MinIOSourceObjectRetentionTimestamp = "X-Minio-Source-Replication-Retention-Timestamp"
	// Header indiicates last rtention update time on source
	MinIOSourceObjectLegalHoldTimestamp = "X-Minio-Source-Replication-LegalHold-Timestamp"
	// predicted date/time of transition
	MinIOTransition            = "X-Minio-Transition"
	MinIOLifecycleCfgUpdatedAt = "X-Minio-LifecycleConfig-UpdatedAt"
	// MinIOCompressed is returned when object is compressed
	MinIOCompressed = "X-Minio-Compressed"

	// SUBNET related
	SubnetAPIKey = "x-subnet-api-key"
)

Standard S3 HTTP request constants

View Source
const (
	VersionID = "versionId"

	PartNumber = "partNumber"

	UploadID = "uploadId"
)

Common http query params S3 API

View Source
const (
	AmzRequestRoute = "x-amz-request-route"
	AmzRequestToken = "x-amz-request-token"

	AmzFwdStatus                   = "x-amz-fwd-status"
	AmzFwdErrorCode                = "x-amz-fwd-error-code"
	AmzFwdErrorMessage             = "x-amz-fwd-error-message"
	AmzFwdHeaderAcceptRanges       = "x-amz-fwd-header-accept-ranges"
	AmzFwdHeaderCacheControl       = "x-amz-fwd-header-Cache-Control"
	AmzFwdHeaderContentDisposition = "x-amz-fwd-header-Content-Disposition"
	AmzFwdHeaderContentEncoding    = "x-amz-fwd-header-Content-Encoding"
	AmzFwdHeaderContentLanguage    = "x-amz-fwd-header-Content-Language"
	AmzFwdHeaderContentRange       = "x-amz-fwd-header-Content-Range"
	AmzFwdHeaderContentType        = "x-amz-fwd-header-Content-Type"
	AmzFwdHeaderChecksumCrc32      = "x-amz-fwd-header-x-amz-checksum-crc32"
	AmzFwdHeaderChecksumCrc32c     = "x-amz-fwd-header-x-amz-checksum-crc32c"
	AmzFwdHeaderChecksumSha1       = "x-amz-fwd-header-x-amz-checksum-sha1"
	AmzFwdHeaderChecksumSha256     = "x-amz-fwd-header-x-amz-checksum-sha256"
	AmzFwdHeaderDeleteMarker       = "x-amz-fwd-header-x-amz-delete-marker"
	AmzFwdHeaderETag               = "x-amz-fwd-header-ETag"
	AmzFwdHeaderExpires            = "x-amz-fwd-header-Expires"
	AmzFwdHeaderExpiration         = "x-amz-fwd-header-x-amz-expiration"
	AmzFwdHeaderLastModified       = "x-amz-fwd-header-Last-Modified"

	AmzFwdHeaderObjectLockMode        = "x-amz-fwd-header-x-amz-object-lock-mode"
	AmzFwdHeaderObjectLockLegalHold   = "x-amz-fwd-header-x-amz-object-lock-legal-hold"
	AmzFwdHeaderObjectLockRetainUntil = "x-amz-fwd-header-x-amz-object-lock-retain-until-date"
	AmzFwdHeaderMPPartsCount          = "x-amz-fwd-header-x-amz-mp-parts-count"
	AmzFwdHeaderReplicationStatus     = "x-amz-fwd-header-x-amz-replication-status"
	AmzFwdHeaderSSE                   = "x-amz-fwd-header-x-amz-server-side-encryption"
	AmzFwdHeaderSSEC                  = "x-amz-fwd-header-x-amz-server-side-encryption-customer-algorithm"
	AmzFwdHeaderSSEKMSID              = "x-amz-fwd-header-x-amz-server-side-encryption-aws-kms-key-id"
	AmzFwdHeaderSSECMD5               = "x-amz-fwd-header-x-amz-server-side-encryption-customer-key-MD5"
	AmzFwdHeaderStorageClass          = "x-amz-fwd-header-x-amz-storage-class"
	AmzFwdHeaderTaggingCount          = "x-amz-fwd-header-x-amz-tagging-count"
	AmzFwdHeaderVersionID             = "x-amz-fwd-header-x-amz-version-id"
)

Object Lambda headers

View Source
const (

	// DefaultShutdownTimeout - default shutdown timeout to gracefully shutdown server.
	DefaultShutdownTimeout = 5 * time.Second

	// DefaultIdleTimeout for idle inactive connections
	DefaultIdleTimeout = 30 * time.Second

	// DefaultReadHeaderTimeout for very slow inactive connections
	DefaultReadHeaderTimeout = 30 * time.Second

	// DefaultMaxHeaderBytes - default maximum HTTP header size in bytes.
	DefaultMaxHeaderBytes = 1 * humanize.MiByte
)
View Source
const (
	// Reports the version of MinIO server
	MinIOVersion = "x-minio-version"
)

http headers sent to webhook targets

Variables

View Source
var (
	// GlobalMinIOVersion - is sent in the header to all http targets
	GlobalMinIOVersion string

	// GlobalDeploymentID - is sent in the header to all http targets
	GlobalDeploymentID string
)

Functions

func CheckPortAvailability

func CheckPortAvailability(host, port string, opts TCPOptions) (err error)

CheckPortAvailability - check if given host and port is already in use. Note: The check method tries to listen on given port and closes it. It is possible to have a disconnected client in this tiny window of time.

func DrainBody

func DrainBody(respBody io.ReadCloser)

DrainBody close non nil response with any response Body. convenient wrapper to drain any remaining data on response body.

Subsequently this allows golang http RoundTripper to re-use the same connection for future requests.

func SetDeploymentID

func SetDeploymentID(deploymentID string)

SetDeploymentID -- Deployment Id from the main package is set here

func SetMinIOVersion

func SetMinIOVersion(version string)

SetMinIOVersion -- MinIO version from the main package is set here

Types

type ConnSettings

type ConnSettings struct {
	DialContext DialContext // Custom dialContext, DialTimeout is ignored if this is already setup.
	LookupHost  LookupHost  // Custom lookupHost, is nil on containerized deployments.
	DialTimeout time.Duration

	// TLS Settings
	RootCAs          *x509.CertPool
	CipherSuites     []uint16
	CurvePreferences []tls.CurveID

	// HTTP2
	EnableHTTP2 bool

	// TCP Options
	TCPOptions TCPOptions
}

ConnSettings - contains connection settings.

func (ConnSettings) NewCustomHTTPProxyTransport

func (s ConnSettings) NewCustomHTTPProxyTransport() func() *http.Transport

NewCustomHTTPProxyTransport is used only for proxied requests, specifically only supports HTTP/1.1

func (ConnSettings) NewHTTPTransportWithClientCerts

func (s ConnSettings) NewHTTPTransportWithClientCerts(ctx context.Context, clientCert, clientKey string) (*http.Transport, error)

NewHTTPTransportWithClientCerts returns a new http configuration used for communicating with client cert authentication.

func (ConnSettings) NewHTTPTransportWithTimeout

func (s ConnSettings) NewHTTPTransportWithTimeout(timeout time.Duration) *http.Transport

NewHTTPTransportWithTimeout allows setting a timeout for response headers

func (ConnSettings) NewInternodeHTTPTransport

func (s ConnSettings) NewInternodeHTTPTransport() func() http.RoundTripper

NewInternodeHTTPTransport returns transport for internode MinIO connections.

func (ConnSettings) NewRemoteTargetHTTPTransport

func (s ConnSettings) NewRemoteTargetHTTPTransport(insecure bool) func() *http.Transport

NewRemoteTargetHTTPTransport returns a new http configuration used while communicating with the remote replication targets.

type DialContext

type DialContext func(ctx context.Context, network, address string) (net.Conn, error)

DialContext is a function to make custom Dial for internode communications

func DialContextWithLookupHost

func DialContextWithLookupHost(lookupHost LookupHost, baseDialCtx DialContext) DialContext

DialContextWithLookupHost is a helper function which returns `net.DialContext` function. It randomly fetches an IP via custom LookupHost function and dials it by the given dial function. LookupHost may implement an internal DNS caching implementation, lookupHost input if nil then net.DefaultResolver.LookupHost is used.

It dials one by one and returns first connected `net.Conn`. If it fails to dial all IPs from cache it returns first error. If no baseDialFunc is given, it sets default dial function.

You can use returned dial function for `http.Transport.DialContext`.

In this function, it uses functions from `rand` package. To make it really random, you MUST call `rand.Seed` and change the value from the default in your application

func NewCustomDialContext

func NewCustomDialContext(dialTimeout time.Duration, opts TCPOptions) DialContext

NewCustomDialContext setups a custom dialer for any external communication and proxies.

func NewInternodeDialContext

func NewInternodeDialContext(dialTimeout time.Duration, opts TCPOptions) DialContext

NewInternodeDialContext setups a custom dialer for internode communication

type LookupHost

type LookupHost func(ctx context.Context, host string) (addrs []string, err error)

LookupHost is a function to make custom lookupHost for optional cached DNS requests

type RequestRecorder

type RequestRecorder struct {
	// Data source to record
	io.Reader
	// Response body should be logged
	LogBody bool
	// contains filtered or unexported fields
}

RequestRecorder - records the of a given io.Reader

func (*RequestRecorder) Close

func (r *RequestRecorder) Close() error

Close is a no operation closer

func (*RequestRecorder) Data

func (r *RequestRecorder) Data() []byte

Data returns the bytes that were recorded.

func (*RequestRecorder) Read

func (r *RequestRecorder) Read(p []byte) (n int, err error)

Read reads from the internal reader and counts/save the body in the memory

func (*RequestRecorder) Size

func (r *RequestRecorder) Size() int

Size returns the body size if the currently read object

type ResponseRecorder

type ResponseRecorder struct {
	http.ResponseWriter
	StatusCode int
	// Log body of 4xx or 5xx responses
	LogErrBody bool
	// Log body of all responses
	LogAllBody bool

	TimeToFirstByte time.Duration
	StartTime       time.Time
	// contains filtered or unexported fields
}

ResponseRecorder - is a wrapper to trap the http response status code and to record the response body

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter) *ResponseRecorder

NewResponseRecorder - returns a wrapped response writer to trap http status codes for auditing purposes.

func (*ResponseRecorder) Body

func (lrw *ResponseRecorder) Body() []byte

Body - Return response body.

func (*ResponseRecorder) Flush

func (lrw *ResponseRecorder) Flush()

Flush - Calls the underlying Flush.

func (*ResponseRecorder) HeaderSize

func (lrw *ResponseRecorder) HeaderSize() int

HeaderSize - returns the number of bytes of response headers written

func (*ResponseRecorder) Size

func (lrw *ResponseRecorder) Size() int

Size - returns the number of bytes written

func (*ResponseRecorder) Write

func (lrw *ResponseRecorder) Write(p []byte) (int, error)

func (*ResponseRecorder) WriteHeader

func (lrw *ResponseRecorder) WriteHeader(code int)

WriteHeader - writes http status code

type Server

type Server struct {
	http.Server
	Addrs           []string      // addresses on which the server listens for new connection.
	TCPOptions      TCPOptions    // all the configurable TCP conn specific configurable options.
	ShutdownTimeout time.Duration // timeout used for graceful server shutdown.
	// contains filtered or unexported fields
}

Server - extended http.Server supports multiple addresses to serve and enhanced connection handling.

func NewServer

func NewServer(addrs []string) *Server

NewServer - creates new HTTP server using given arguments.

func (*Server) GetRequestCount

func (srv *Server) GetRequestCount() int

GetRequestCount - returns number of request in progress.

func (*Server) Init

func (srv *Server) Init(listenCtx context.Context, listenErrCallback func(listenAddr string, err error)) (serve func() error, err error)

Init - init HTTP server

func (*Server) Shutdown

func (srv *Server) Shutdown() error

Shutdown - shuts down HTTP server.

func (*Server) UseBaseContext

func (srv *Server) UseBaseContext(ctx context.Context) *Server

UseBaseContext use custom base context for this HTTP *Server

func (*Server) UseCustomLogger

func (srv *Server) UseCustomLogger(l *log.Logger) *Server

UseCustomLogger use customized logger for this HTTP *Server

func (*Server) UseHandler

func (srv *Server) UseHandler(h http.Handler) *Server

UseHandler configure final handler for this HTTP *Server

func (*Server) UseIdleTimeout

func (srv *Server) UseIdleTimeout(d time.Duration) *Server

UseIdleTimeout configure idle connection timeout

func (*Server) UseReadHeaderTimeout

func (srv *Server) UseReadHeaderTimeout(d time.Duration) *Server

UseReadHeaderTimeout configure read header timeout

func (*Server) UseShutdownTimeout

func (srv *Server) UseShutdownTimeout(d time.Duration) *Server

UseShutdownTimeout configure server shutdown timeout

func (*Server) UseTCPOptions

func (srv *Server) UseTCPOptions(opts TCPOptions) *Server

UseTCPOptions use custom TCP options on raw socket

func (*Server) UseTLSConfig

func (srv *Server) UseTLSConfig(cfg *tls.Config) *Server

UseTLSConfig pass configured TLSConfig for this HTTP *Server

type TCPOptions

type TCPOptions struct {
	UserTimeout int              // this value is expected to be in milliseconds
	Interface   string           // this is a VRF device passed via `--interface` flag
	Trace       func(msg string) // Trace when starting.
}

TCPOptions specify customizable TCP optimizations on raw socket

Jump to

Keyboard shortcuts

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