mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +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
|
package blob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/lib/errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"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/lib/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/distribution"
|
"github.com/goharbor/harbor/src/pkg/distribution"
|
||||||
"github.com/goharbor/harbor/src/server/middleware"
|
"github.com/goharbor/harbor/src/server/middleware"
|
||||||
@ -32,6 +33,7 @@ func PutManifestMiddleware() func(http.Handler) http.Handler {
|
|||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
logger := log.G(ctx)
|
logger := log.G(ctx)
|
||||||
|
|
||||||
|
lib.NopCloseRequest(r) // make the r.Body re-readable
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
lib_http "github.com/goharbor/harbor/src/lib/http"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/lib"
|
"github.com/goharbor/harbor/src/lib"
|
||||||
|
lib_http "github.com/goharbor/harbor/src/lib/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Middleware receives a handler and returns another handler.
|
// 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
|
// 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 {
|
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) {
|
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)
|
lib_http.SendError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user