package httputil
import "github.com/rootless-containers/rootlesskit/v2/pkg/httputil"
Index ¶
- Constants
- func NewHTTPClient(socketPath string) (*http.Client, error)
- func Successful(resp *http.Response) error
- func WriteError(w http.ResponseWriter, r *http.Request, err error, ec int)
- type ErrorJSON
- type HTTPStatusError
Constants ¶
const HTTPStatusErrorBodyMaxLength = 64 * 1024
HTTPStatusErrorBodyMaxLength specifies the maximum length of HTTPStatusError.Body
Functions ¶
func NewHTTPClient ¶
func Successful ¶
Successful returns an error if the status code is not 2xx.
func WriteError ¶
WriteError writes an error. WriteError sould not be used if an error may contain sensitive information and the client is not reliable.
Types ¶
type ErrorJSON ¶
type ErrorJSON struct { Message string `json:"message"` }
ErrorJSON is returned with "application/json" content type and non-2XX status code
type HTTPStatusError ¶
type HTTPStatusError struct { // StatusCode is non-2XX status code StatusCode int // Body is at most HTTPStatusErrorBodyMaxLength Body string }
HTTPStatusError is created from non-2XX HTTP response
func (*HTTPStatusError) Error ¶
func (e *HTTPStatusError) Error() string
Error implements error. If e.Body is a marshalled string of api.ErrorJSON, Error returns ErrorJSON.Message . Otherwise Error returns a human-readable string that contains e.StatusCode and e.Body.
Source Files ¶
- Version
- v2.3.4 (latest)
- Published
- Mar 10, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 3 weeks ago –
Tools for package owners.