mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 20:26:13 +01:00
Merge pull request #13557 from heww/fix-issue-13556
fix: remove auto re-readable body in BeforeRequest
This commit is contained in:
commit
00c941a413
@ -15,10 +15,11 @@
|
||||
package blob
|
||||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/goharbor/harbor/src/lib"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/distribution"
|
||||
"github.com/goharbor/harbor/src/server/middleware"
|
||||
@ -32,6 +33,7 @@ func PutManifestMiddleware() func(http.Handler) http.Handler {
|
||||
ctx := r.Context()
|
||||
logger := log.G(ctx)
|
||||
|
||||
lib.NopCloseRequest(r) // make the r.Body re-readable
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -15,10 +15,10 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
lib_http "github.com/goharbor/harbor/src/lib/http"
|
||||
"net/http"
|
||||
|
||||
"github.com/goharbor/harbor/src/lib"
|
||||
lib_http "github.com/goharbor/harbor/src/lib/http"
|
||||
)
|
||||
|
||||
// Middleware receives a handler and returns another handler.
|
||||
@ -62,7 +62,7 @@ func New(fn func(http.ResponseWriter, *http.Request, http.Handler), skippers ...
|
||||
// BeforeRequest make a middleware which will call hook before the next handler
|
||||
func BeforeRequest(hook func(*http.Request) error, skippers ...Skipper) func(http.Handler) http.Handler {
|
||||
return New(func(w http.ResponseWriter, r *http.Request, next http.Handler) {
|
||||
if err := hook(lib.NopCloseRequest(r)); err != nil {
|
||||
if err := hook(r); err != nil {
|
||||
lib_http.SendError(w, err)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user