diff options
| author | 2025-11-05 21:58:38 +0100 | |
|---|---|---|
| committer | 2025-11-17 14:12:41 +0100 | |
| commit | d0c551acb5ab79efafd325f5b19c76a3de835356 (patch) | |
| tree | ba9462cdc5081015fbd6bf5d98d9f39334d13207 /vendor/github.com/minio/minio-go/v7/api.go | |
| parent | [performance] when transforming media, perform read operations of large files... (diff) | |
| download | gotosocial-d0c551acb5ab79efafd325f5b19c76a3de835356.tar.xz | |
[chore] update dependencies (#4542)
- github.com/minio/minio-go/v7: v7.0.95 -> v7.0.97
- github.com/ncruces/go-sqlite3: v0.29.1 -> v0.30.0
- github.com/tdewolff/minify/v2: v2.24.5 -> v2.24.6
- codeberg.org/gruf/go-mmap: fixes build for BSD platforms
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4542
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/github.com/minio/minio-go/v7/api.go')
| -rw-r--r-- | vendor/github.com/minio/minio-go/v7/api.go | 117 |
1 files changed, 51 insertions, 66 deletions
diff --git a/vendor/github.com/minio/minio-go/v7/api.go b/vendor/github.com/minio/minio-go/v7/api.go index 53ef6b85a..5352d793b 100644 --- a/vendor/github.com/minio/minio-go/v7/api.go +++ b/vendor/github.com/minio/minio-go/v7/api.go @@ -21,7 +21,6 @@ import ( "bytes" "context" "encoding/base64" - "encoding/xml" "errors" "fmt" "io" @@ -43,7 +42,6 @@ import ( md5simd "github.com/minio/md5-simd" "github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/kvcache" - "github.com/minio/minio-go/v7/pkg/peeker" "github.com/minio/minio-go/v7/pkg/s3utils" "github.com/minio/minio-go/v7/pkg/signer" "github.com/minio/minio-go/v7/pkg/singleflight" @@ -162,7 +160,7 @@ type Options struct { // Global constants. const ( libraryName = "minio-go" - libraryVersion = "v7.0.95" + libraryVersion = "v7.0.96" ) // User Agent should always following the below style. @@ -204,7 +202,9 @@ func New(endpoint string, opts *Options) (*Client, error) { return clnt, nil } -// EndpointURL returns the URL of the S3 endpoint. +// EndpointURL returns the URL of the S3-compatible endpoint that this client connects to. +// +// Returns a copy of the endpoint URL to prevent modification of internal state. func (c *Client) EndpointURL() *url.URL { endpoint := *c.endpointURL // copy to prevent callers from modifying internal state return &endpoint @@ -221,7 +221,7 @@ func (r *lockedRandSource) Int63() (n int64) { r.lk.Lock() n = r.src.Int63() r.lk.Unlock() - return + return n } // Seed uses the provided seed value to initialize the generator to a @@ -325,7 +325,14 @@ func privateNew(endpoint string, opts *Options) (*Client, error) { return clnt, nil } -// SetAppInfo - add application details to user agent. +// SetAppInfo adds custom application name and version to the User-Agent header for all requests. +// This helps identify your application in server logs and metrics. +// +// Parameters: +// - appName: Name of the application +// - appVersion: Version of the application +// +// Both parameters must be non-empty for the custom User-Agent to be set. func (c *Client) SetAppInfo(appName, appVersion string) { // if app name and version not set, we do not set a new user agent. if appName != "" && appVersion != "" { @@ -334,7 +341,11 @@ func (c *Client) SetAppInfo(appName, appVersion string) { } } -// TraceOn - enable HTTP tracing. +// TraceOn enables HTTP request and response tracing for debugging purposes. +// All HTTP traffic will be written to the provided output stream. +// +// Parameters: +// - outputStream: Writer where trace output will be written (defaults to os.Stdout if nil) func (c *Client) TraceOn(outputStream io.Writer) { // if outputStream is nil then default to os.Stdout. if outputStream == nil { @@ -347,19 +358,23 @@ func (c *Client) TraceOn(outputStream io.Writer) { c.isTraceEnabled = true } -// TraceErrorsOnlyOn - same as TraceOn, but only errors will be traced. +// TraceErrorsOnlyOn enables HTTP tracing but only for requests that result in errors. +// This is useful for debugging without the overhead of tracing all requests. +// +// Parameters: +// - outputStream: Writer where trace output will be written (defaults to os.Stdout if nil) func (c *Client) TraceErrorsOnlyOn(outputStream io.Writer) { c.TraceOn(outputStream) c.traceErrorsOnly = true } -// TraceErrorsOnlyOff - Turns off the errors only tracing and everything will be traced after this call. -// If all tracing needs to be turned off, call TraceOff(). +// TraceErrorsOnlyOff disables errors-only mode and traces all requests. +// To disable all tracing, call TraceOff() instead. func (c *Client) TraceErrorsOnlyOff() { c.traceErrorsOnly = false } -// TraceOff - disable HTTP tracing. +// TraceOff disables all HTTP tracing (both normal and errors-only modes). func (c *Client) TraceOff() { // Disable tracing. c.isTraceEnabled = false @@ -620,33 +635,11 @@ func (c *Client) do(req *http.Request) (resp *http.Response, err error) { return resp, nil } -// Peek resp.Body looking for S3 XMl error response: -// - Return the error XML bytes if an error is found -// - Make sure to always restablish the whole http response stream before returning -func tryParseErrRespFromBody(resp *http.Response) ([]byte, error) { - peeker := peeker.NewPeekReadCloser(resp.Body, 5*humanize.MiByte) - defer func() { - peeker.ReplayFromStart() - resp.Body = peeker - }() - - errResp := ErrorResponse{} - errBytes, err := xmlDecodeAndBody(peeker, &errResp) - if err != nil { - var unmarshalErr xml.UnmarshalError - if errors.As(err, &unmarshalErr) { - return nil, nil - } - return nil, err - } - return errBytes, nil -} - // List of success status. -var successStatus = []int{ - http.StatusOK, - http.StatusNoContent, - http.StatusPartialContent, +var successStatus = map[int]struct{}{ + http.StatusOK: {}, + http.StatusNoContent: {}, + http.StatusPartialContent: {}, } // executeMethod - instantiates a given method, and retries the @@ -729,29 +722,15 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ return nil, err } - var success bool - var errBodyBytes []byte - - for _, httpStatus := range successStatus { - if httpStatus == res.StatusCode { - success = true - break - } - } - - if success { - if !metadata.expect200OKWithError { - return res, nil - } - errBodyBytes, err = tryParseErrRespFromBody(res) - if err == nil && len(errBodyBytes) == 0 { - // No S3 XML error is found - return res, nil - } - } else { - errBodyBytes, err = io.ReadAll(res.Body) - } + _, success := successStatus[res.StatusCode] + if success && !metadata.expect200OKWithError { + // We do not expect 2xx to return an error return. + return res, nil + } // in all other situations we must first parse the body as ErrorResponse + // 5MiB is sufficiently large enough to hold any error or regular XML response. + var bodyBytes []byte + bodyBytes, err = io.ReadAll(io.LimitReader(res.Body, 5*humanize.MiByte)) // By now, res.Body should be closed closeResponse(res) if err != nil { @@ -759,16 +738,22 @@ func (c *Client) executeMethod(ctx context.Context, method string, metadata requ } // Save the body. - errBodySeeker := bytes.NewReader(errBodyBytes) - res.Body = io.NopCloser(errBodySeeker) + bodySeeker := bytes.NewReader(bodyBytes) + res.Body = io.NopCloser(bodySeeker) - // For errors verify if its retryable otherwise fail quickly. - errResponse := ToErrorResponse(httpRespToErrorResponse(res, metadata.bucketName, metadata.objectName)) - err = errResponse + apiErr := httpRespToErrorResponse(res, metadata.bucketName, metadata.objectName) // Save the body back again. - errBodySeeker.Seek(0, 0) // Seek back to starting point. - res.Body = io.NopCloser(errBodySeeker) + bodySeeker.Seek(0, 0) // Seek back to starting point. + res.Body = io.NopCloser(bodySeeker) + + if apiErr == nil { + return res, nil + } + + // For errors verify if its retryable otherwise fail quickly. + errResponse := ToErrorResponse(apiErr) + err = errResponse // Bucket region if set in error response and the error // code dictates invalid region, we can retry the request |
