fix: extend proxy timeout for Office rendering
This commit is contained in:
+22
-1
@@ -535,6 +535,27 @@ func (a *API) runtimeOriginAllowed(r *http.Request) bool {
|
||||
|
||||
var runtimeTransport = &http.Transport{Proxy: nil, DialContext: (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext, ResponseHeaderTimeout: 20 * time.Second, IdleConnTimeout: 90 * time.Second}
|
||||
|
||||
// Office rendering can take longer than the normal API header deadline (the
|
||||
// bundled converter defaults to 60 seconds). Reuse a separate connection pool
|
||||
// without extending authentication or unrelated runtime requests.
|
||||
var runtimeOfficeTransport = func() *http.Transport {
|
||||
t := runtimeTransport.Clone()
|
||||
t.ResponseHeaderTimeout = 120 * time.Second
|
||||
return t
|
||||
}()
|
||||
|
||||
type runtimeProxyTransport struct {
|
||||
normal, office http.RoundTripper
|
||||
}
|
||||
|
||||
func (t runtimeProxyTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
// ReverseProxy has already removed the instance prefix here.
|
||||
if r.URL.Path == "/api/officeToPdf/render" {
|
||||
return t.office.RoundTrip(r)
|
||||
}
|
||||
return t.normal.RoundTrip(r)
|
||||
}
|
||||
|
||||
type runtimeAuthKey struct {
|
||||
api *API
|
||||
id string
|
||||
@@ -1016,7 +1037,7 @@ func withoutRuntimeToken(rawQuery string) string {
|
||||
|
||||
func runtimeReverseProxy(target *url.URL, prefix, host, cookies string) *httputil.ReverseProxy {
|
||||
return &httputil.ReverseProxy{
|
||||
Transport: runtimeTransport, FlushInterval: -1, ErrorLog: log.New(io.Discard, "", 0),
|
||||
Transport: runtimeProxyTransport{normal: runtimeTransport, office: runtimeOfficeTransport}, FlushInterval: -1, ErrorLog: log.New(io.Discard, "", 0),
|
||||
Rewrite: func(p *httputil.ProxyRequest) {
|
||||
p.SetURL(target)
|
||||
p.Out.Host = host
|
||||
|
||||
Reference in New Issue
Block a user