mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(apigateway): export timeout (#13828)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user