debian-mirror-gitlab/workhorse/internal/upload/accelerate.go

38 lines
1.1 KiB
Go
Raw Normal View History

2021-02-22 17:27:13 +05:30
package upload
import (
"fmt"
"net/http"
2021-11-11 11:23:49 +05:30
"github.com/golang-jwt/jwt/v4"
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
"gitlab.com/gitlab-org/gitlab/workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/helper"
2021-02-22 17:27:13 +05:30
)
const RewrittenFieldsHeader = "Gitlab-Workhorse-Multipart-Fields"
type MultipartClaims struct {
RewrittenFields map[string]string `json:"rewritten_fields"`
jwt.StandardClaims
}
2022-04-04 11:22:00 +05:30
// Multipart is a request middleware. If the request has a MIME multipart
// request body, the middleware will iterate through the multipart parts.
// When it finds a file part (filename != ""), the middleware will save
// the file contents to a temporary location and replace the file part
// with a reference to the temporary location.
func Multipart(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler {
2021-02-22 17:27:13 +05:30
return rails.PreAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *api.Response) {
s := &SavedFileTracker{Request: r}
opts, _, err := p.Prepare(a)
if err != nil {
2022-04-04 11:22:00 +05:30
helper.Fail500(w, r, fmt.Errorf("Multipart: error preparing file storage options"))
2021-02-22 17:27:13 +05:30
return
}
2022-04-04 11:22:00 +05:30
InterceptMultipartFiles(w, r, h, a, s, opts)
2021-02-22 17:27:13 +05:30
}, "/authorize")
}