2018-05-29 13:42:41 +00:00
|
|
|
package multipart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2018-09-25 19:22:25 +00:00
|
|
|
"errors"
|
2018-05-29 13:42:41 +00:00
|
|
|
)
|
|
|
|
|
2018-09-25 19:22:25 +00:00
|
|
|
// ErrMissingDataName is set when a multipart variable/file has no name="..."
|
|
|
|
var ErrMissingDataName = errors.New("data has no name")
|
|
|
|
|
|
|
|
// ErrDataNameConflict is set when a multipart variable/file name is already used
|
|
|
|
var ErrDataNameConflict = errors.New("data name conflict")
|
|
|
|
|
|
|
|
// ErrNoHeader is set when a multipart variable/file has no (valid) header
|
|
|
|
var ErrNoHeader = errors.New("data has no header")
|
|
|
|
|
|
|
|
// Component represents a multipart variable/file
|
|
|
|
type Component struct {
|
|
|
|
// Content Type (raw for variables ; exported from files)
|
|
|
|
ContentType string
|
|
|
|
|
|
|
|
// data headers
|
|
|
|
Headers map[string]string
|
|
|
|
|
|
|
|
// actual data
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
2018-07-08 23:34:21 +00:00
|
|
|
// Reader represents a multipart reader
|
|
|
|
type Reader struct {
|
2018-05-29 13:42:41 +00:00
|
|
|
// reader used for http.Request.Body reading
|
|
|
|
reader *bufio.Reader
|
|
|
|
|
2018-09-25 19:22:25 +00:00
|
|
|
// boundary used to separate multipart MultipartDatas
|
2018-05-29 13:42:41 +00:00
|
|
|
boundary string
|
|
|
|
|
|
|
|
// result will be inside this field
|
2018-09-25 19:22:25 +00:00
|
|
|
Data map[string]*Component
|
2018-05-29 13:42:41 +00:00
|
|
|
}
|