fix(apigateway): export timeout (#13828)

This commit is contained in:
屈轩
2022-03-31 13:51:12 +08:00
committed by GitHub
parent 1378c8a358
commit 042ab4eb02
2 changed files with 16 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import (
"fmt"
"net/http"
"path"
"time"
"yunion.io/x/onecloud/pkg/appsrv"
)
@@ -51,7 +52,17 @@ func (h SHandler) Bind(app *appsrv.Application) {
if h.MiddlewareFunc != nil {
f = h.MiddlewareFunc(f)
}
app.AddHandler(h.Method, h.Prefix, f)
segs := appsrv.SplitPath(h.Prefix)
hi := appsrv.NewHandlerInfo(h.Method, segs, f, nil, "", nil)
if h.Method == "GET" {
hi.SetProcessTimeoutCallback(func(hdr *appsrv.SHandlerInfo, r *http.Request) time.Duration {
if len(r.URL.Query().Get("export_keys")) > 0 {
return time.Hour * 2
}
return -time.Second
})
}
app.AddHandler3(hi)
}
func NewMethodHandlerFactory(method string, mf appsrv.MiddlewareFunc, prefix string) func(handleFunc, ...string) SHandler {

View File

@@ -83,6 +83,10 @@ func (this *SHandlerInfo) GetTags() map[string]string {
return this.tags
}
func NewHandlerInfo(method string, path []string, handler func(context.Context, http.ResponseWriter, *http.Request), metadata map[string]interface{}, name string, tags map[string]string) *SHandlerInfo {
return newHandlerInfo(method, path, handler, metadata, name, tags)
}
func newHandlerInfo(method string, path []string, handler func(context.Context, http.ResponseWriter, *http.Request), metadata map[string]interface{}, name string, tags map[string]string) *SHandlerInfo {
hand := SHandlerInfo{method: method, path: path,
handler: handler,