Skip to content

Commit

Permalink
Allow POST method to request service/token in readonly mode
Browse files Browse the repository at this point in the history
  fixes #18243

Signed-off-by: stonezdj <daojunz@vmware.com>
  • Loading branch information
stonezdj committed Nov 10, 2023
1 parent 5c02fd8 commit e461b87
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/middlewares/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import (
)

var (
match = regexp.MustCompile
numericRegexp = match(`[0-9]+`)
match = regexp.MustCompile
numericRegexp = match(`[0-9]+`)
serviceTokenRegexp = match(`^/service/token`)

// The ping endpoint will be blocked when DB conns reach the max open conns of the sql.DB
// which will make ping request timeout, so skip the middlewares which will require DB conn.
Expand All @@ -54,6 +55,7 @@ var (
dbTxSkippers = []middleware.Skipper{
middleware.MethodAndPathSkipper(http.MethodPatch, distribution.BlobUploadURLRegexp),
middleware.MethodAndPathSkipper(http.MethodPut, distribution.BlobUploadURLRegexp),
middleware.MethodAndPathSkipper(http.MethodPost, serviceTokenRegexp),
func(r *http.Request) bool { // skip tx for GET, HEAD and Options requests
m := r.Method
return m == http.MethodGet || m == http.MethodHead || m == http.MethodOptions
Expand All @@ -72,6 +74,7 @@ var (
middleware.MethodAndPathSkipper(http.MethodPost, match("^/service/notifications/jobs/replication/task/"+numericRegexp.String())),
middleware.MethodAndPathSkipper(http.MethodPost, match("^/service/notifications/jobs/retention/task/"+numericRegexp.String())),
middleware.MethodAndPathSkipper(http.MethodPost, match("^/service/notifications/jobs/schedules/"+numericRegexp.String())),
middleware.MethodAndPathSkipper(http.MethodPost, serviceTokenRegexp),
pingSkipper,
}
)
Expand Down

0 comments on commit e461b87

Please sign in to comment.