parse

package
v5.0.0-rc5 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	goyave.Component

	// MaxUpoadSize the maximum size of the request (in MiB).
	// Defaults to the value provided in the config "server.maxUploadSize".
	MaxUploadSize float64
}

Middleware reading the raw request query and body.

First, the query is parsed using Go's standard `url.ParseQuery()`. After being flattened (single value arrays converted to non-array), the result is put in the request's `Query`. If the parsing fails, returns "400 Bad request".

The body is read only if the "Content-Type" header is set. If the body exceeds the configured max upload size (in MiB), "413 Request Entity Too Large" is returned. If the content type is "application/json", the middleware will attempt to unmarshal the body and put the result in the request's `Data`. If it fails, returns "400 Bad request". If the content-type has another value, Go's standard `ParseMultipartForm` is called. The result is put inside the request's `Data` after being flattened. If the form is not a multipart form, attempts `ParseForm`. If `ParseMultipartForm` or `ParseForm` return an error, returns "400 Bad request".

func (*Middleware) Handle

func (m *Middleware) Handle(next goyave.Handler) goyave.Handler

Handle reads the request query and body and parses it if necessary. If the request Data is not nil, the body is not parsed again and the middleware immediately passes after parsing the query.

Jump to

Keyboard shortcuts

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