httprequest

package
v1.8.30 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 25 Imported by: 8 modules, 18 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FormDataMaxMemory = 256 << 20 // 256 MB
)
View Source
const (
	// FormValueMaxSize is the largest value of a form, other than a file,
	// which Binary reads
	FormValueMaxSize = 1 << 20 // 1 MB
)

Variables

This section is empty.

Functions

func Binary added in v1.7.16

func Binary(r *http.Request, fn func(field string, values url.Values, file types.File) error) (url.Values, error)

Binary reads the files uploaded with a request, as httpresponse.Binary writes a file in a response. It calls fn for each file, in order, with the name of its form field, the form's values which were before it, and the file, whose body is streamed from the request, so it's only read in fn, and isn't held in memory or in a temporary file, as Read holds it.

The parts of a multipart/form-data request with a file name are files, and its other parts are values, which are passed to fn as far as they've been read, so a value sent before a file, as browsers and go-client send a form's fields in order, is known with it. A value larger than FormValueMaxSize is an error. The body of any other request is one file, whose field name and path are empty, with the request's headers.

A file's path keeps its directories, from its X-Path part header, as go-client sends it, or the file name in its Content-Disposition, as a browser sends a folder's files, cleaned, and without a leading slash, so it can be joined to a directory. A path which would be above it is the file name alone. A file's modified time is from its Last-Modified header, when it's set.

A large file can take longer to read than the server's read timeout, so a caller can clear the read deadline before, with http.ResponseController. Returns the form's values, which are all of them when there's no error, and the error from fn, including an error reading a file's body, or reading the form's parts or values, which is a bad request.

func Indent

func Indent(r *http.Request) int

func NewPathItem added in v1.6.19

func NewPathItem(summary, description string, tags ...string) *pathitem

NewPathItem creates a new path item with the given summary, description and tags.

func Query

func Query(q url.Values, v any) error

Read the request query parameters into a structure

func Read

func Read(r *http.Request, v interface{}) error

Read the request body into a structure

Types

type PathItem added in v1.6.19

type PathItem interface {
	// Add one or more tags to the path item.
	// Tags are used to group operations in the OpenAPI document.
	Tag(...string) PathItem

	// Get registers a GET handler with the given summary and operation options.
	Get(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Put registers a PUT handler with the given summary and operation options.
	Put(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Post registers a POST handler with the given summary and operation options.
	Post(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Delete registers a DELETE handler with the given summary and operation options.
	Delete(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Patch registers a PATCH handler with the given summary and operation options.
	Patch(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Options registers an OPTIONS handler with the given summary and operation options.
	Options(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Head registers a HEAD handler with the given summary and operation options.
	Head(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Trace registers a TRACE handler with the given summary and operation options.
	Trace(handler http.HandlerFunc, fn func(PathOperation)) PathItem

	// Handler returns the http.HandlerFunc that handles the PathItem
	Handler() http.HandlerFunc

	// Spec returns the openapi.PathItem for a path with optional path parameters
	Spec(string, *jsonschema.Schema) *openapi.PathItem

	// WrapHandler wraps the handler for a specific HTTP method with middleware.
	// The method should be an uppercase HTTP method name (GET, POST, etc.).
	// If no handler is registered for the method, the call is a no-op.
	WrapHandler(method string, fn func(http.HandlerFunc) http.HandlerFunc)
}

type PathOperation added in v1.7.0

type PathOperation interface {
	// Add one or more tags to the operation.
	Tags(...string) PathOperation

	// Set the summary for the operation.
	Summary(string) PathOperation

	// Set the description for the operation.
	Description(string) PathOperation

	// Set the query parameters for the operation from a JSON schema.
	Query(*jsonschema.Schema) PathOperation

	// Mark the operation as deprecated.
	Deprecated() PathOperation

	// Add a request body for the operation with the given schema, for each of the
	// content types, or "application/json" if none is provided. It can be called
	// more than once, to accept content types with different schemas, such as
	// JSON and a multipart form.
	RequestBody(schema *jsonschema.Schema, contentType ...string) PathOperation

	// Add a JSON response for the operation with the given status code and schema.
	// An optional description can be provided; if not, the default HTTP status text will be used.
	// A response with another content type for the same status code is kept, so a status code
	// can have more than one content type.
	JSONResponse(status int, schema *jsonschema.Schema, description ...string) PathOperation

	// Add a text/event-stream response for the operation with the given status code, for a
	// stream of server-sent events. An optional description can be provided; if not, the
	// default HTTP status text will be used. A response with another content type for the
	// same status code is kept.
	TextStreamResponse(status int, description ...string) PathOperation

	// Add an error response for the operation with the given status code.
	// An optional description can be provided; if not, the default HTTP status text will be used.
	ErrorResponse(status int, description ...string) PathOperation

	// Add a 204 No Content response, without content, for the operation. An optional
	// description can be provided; if not, the default HTTP status text will be used.
	EmptyResponse(description ...string) PathOperation

	// Return a response for the operation with the given status code and content type.
	// An optional description can be provided; if not, the default HTTP status text will be used.
	// A response with another content type for the same status code is kept. An empty content
	// type is a response without content, such as 304 Not Modified.
	Response(status int, contentType string, description ...string) PathOperation

	// Require the named security scheme, with optional scopes, for the operation.
	// The scheme must be registered with the router before the path is registered.
	// Calling Security more than once adds alternatives, any of which grants
	// access, which the router runs at once, as SecurityScheme says.
	Security(scheme string, scopes ...string) PathOperation
}

Jump to

Keyboard shortcuts

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