Make sure PATCH request has application/offset+octet-stream
This commit is contained in:
parent
86dc420ebe
commit
1f6aac2a49
|
@ -22,6 +22,7 @@ var reExtractFileID = regexp.MustCompile(`([^/]+)\/?$`)
|
||||||
var (
|
var (
|
||||||
ErrUnsupportedVersion = errors.New("unsupported version")
|
ErrUnsupportedVersion = errors.New("unsupported version")
|
||||||
ErrMaxSizeExceeded = errors.New("maximum size exceeded")
|
ErrMaxSizeExceeded = errors.New("maximum size exceeded")
|
||||||
|
ErrInvalidContentType = errors.New("missing or invalid Content-Type header")
|
||||||
ErrInvalidUploadLength = errors.New("missing or invalid Upload-Length header")
|
ErrInvalidUploadLength = errors.New("missing or invalid Upload-Length header")
|
||||||
ErrInvalidOffset = errors.New("missing or invalid Upload-Offset header")
|
ErrInvalidOffset = errors.New("missing or invalid Upload-Offset header")
|
||||||
ErrNotFound = errors.New("upload not found")
|
ErrNotFound = errors.New("upload not found")
|
||||||
|
@ -38,6 +39,7 @@ var (
|
||||||
var ErrStatusCodes = map[error]int{
|
var ErrStatusCodes = map[error]int{
|
||||||
ErrUnsupportedVersion: http.StatusPreconditionFailed,
|
ErrUnsupportedVersion: http.StatusPreconditionFailed,
|
||||||
ErrMaxSizeExceeded: http.StatusRequestEntityTooLarge,
|
ErrMaxSizeExceeded: http.StatusRequestEntityTooLarge,
|
||||||
|
ErrInvalidContentType: http.StatusBadRequest,
|
||||||
ErrInvalidUploadLength: http.StatusBadRequest,
|
ErrInvalidUploadLength: http.StatusBadRequest,
|
||||||
ErrInvalidOffset: http.StatusBadRequest,
|
ErrInvalidOffset: http.StatusBadRequest,
|
||||||
ErrNotFound: http.StatusNotFound,
|
ErrNotFound: http.StatusNotFound,
|
||||||
|
@ -275,6 +277,13 @@ func (handler *Handler) headFile(w http.ResponseWriter, r *http.Request) {
|
||||||
// Add a chunk to an upload. Only allowed if the upload is not locked and enough
|
// Add a chunk to an upload. Only allowed if the upload is not locked and enough
|
||||||
// space is left.
|
// space is left.
|
||||||
func (handler *Handler) patchFile(w http.ResponseWriter, r *http.Request) {
|
func (handler *Handler) patchFile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
//Check for presence of application/offset+octet-stream
|
||||||
|
if r.Header.Get("Content-Type") != "application/offset+octet-stream" {
|
||||||
|
handler.sendError(w, r, ErrInvalidContentType)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
id := r.URL.Query().Get(":id")
|
id := r.URL.Query().Get(":id")
|
||||||
|
|
||||||
// Ensure file is not locked
|
// Ensure file is not locked
|
||||||
|
|
Loading…
Reference in New Issue