fix(webdav): Set Retry-After header for 429 responses
We're now setting a 'Retry-After' in the webdav response when the thunbnailer is rate limiting the requests. For now the timeout is just a random number between 1 and 15 seconds.
This commit is contained in:
committed by
Ralf Haferkamp
parent
74d54579cb
commit
f536dacd4d
@@ -3,5 +3,8 @@ Bugfix: Thumbnail request limit
|
|||||||
The `THUMBNAILS_MAX_CONCURRENT_REQUESTS` setting was not working correctly.
|
The `THUMBNAILS_MAX_CONCURRENT_REQUESTS` setting was not working correctly.
|
||||||
Previously it was just limiting the number of concurrent thumbnail downloads.
|
Previously it was just limiting the number of concurrent thumbnail downloads.
|
||||||
Now the limit is applied to the number thumbnail generations requests.
|
Now the limit is applied to the number thumbnail generations requests.
|
||||||
|
Additionally the webdav service is now returning a "Retry-After" header when
|
||||||
|
it is hitting the ratelimit of the thumbnail service.
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/10280
|
||||||
https://github.com/owncloud/ocis/pull/10225
|
https://github.com/owncloud/ocis/pull/10225
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand/v2"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||||
@@ -259,6 +261,7 @@ func (g Webdav) SpacesThumbnail(w http.ResponseWriter, r *http.Request) {
|
|||||||
renderError(w, r, errTooEarly(e.Detail))
|
renderError(w, r, errTooEarly(e.Detail))
|
||||||
return
|
return
|
||||||
case http.StatusTooManyRequests:
|
case http.StatusTooManyRequests:
|
||||||
|
addRetryAfterHeader(w)
|
||||||
renderError(w, r, errTooManyRequests(e.Detail))
|
renderError(w, r, errTooManyRequests(e.Detail))
|
||||||
case http.StatusBadRequest:
|
case http.StatusBadRequest:
|
||||||
renderError(w, r, errBadRequest(e.Detail))
|
renderError(w, r, errBadRequest(e.Detail))
|
||||||
@@ -356,6 +359,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
|
|||||||
renderError(w, r, errTooEarly(e.Detail))
|
renderError(w, r, errTooEarly(e.Detail))
|
||||||
return
|
return
|
||||||
case http.StatusTooManyRequests:
|
case http.StatusTooManyRequests:
|
||||||
|
addRetryAfterHeader(w)
|
||||||
renderError(w, r, errTooManyRequests(e.Detail))
|
renderError(w, r, errTooManyRequests(e.Detail))
|
||||||
case http.StatusBadRequest:
|
case http.StatusBadRequest:
|
||||||
renderError(w, r, errBadRequest(e.Detail))
|
renderError(w, r, errBadRequest(e.Detail))
|
||||||
@@ -404,6 +408,7 @@ func (g Webdav) PublicThumbnail(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.StatusBadRequest:
|
case http.StatusBadRequest:
|
||||||
renderError(w, r, errBadRequest(e.Detail))
|
renderError(w, r, errBadRequest(e.Detail))
|
||||||
case http.StatusTooManyRequests:
|
case http.StatusTooManyRequests:
|
||||||
|
addRetryAfterHeader(w)
|
||||||
renderError(w, r, errTooManyRequests(e.Detail))
|
renderError(w, r, errTooManyRequests(e.Detail))
|
||||||
default:
|
default:
|
||||||
renderError(w, r, errInternalError(err.Error()))
|
renderError(w, r, errInternalError(err.Error()))
|
||||||
@@ -448,6 +453,7 @@ func (g Webdav) PublicThumbnailHead(w http.ResponseWriter, r *http.Request) {
|
|||||||
case http.StatusBadRequest:
|
case http.StatusBadRequest:
|
||||||
renderError(w, r, errBadRequest(e.Detail))
|
renderError(w, r, errBadRequest(e.Detail))
|
||||||
case http.StatusTooManyRequests:
|
case http.StatusTooManyRequests:
|
||||||
|
addRetryAfterHeader(w)
|
||||||
renderError(w, r, errTooManyRequests(e.Detail))
|
renderError(w, r, errTooManyRequests(e.Detail))
|
||||||
default:
|
default:
|
||||||
renderError(w, r, errInternalError(err.Error()))
|
renderError(w, r, errInternalError(err.Error()))
|
||||||
@@ -566,3 +572,8 @@ func renderError(w http.ResponseWriter, r *http.Request, err *errResponse) {
|
|||||||
func notFoundMsg(name string) string {
|
func notFoundMsg(name string) string {
|
||||||
return "File with name " + name + " could not be located"
|
return "File with name " + name + " could not be located"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addRetryAfterHeader(w http.ResponseWriter) {
|
||||||
|
after := rand.IntN(14) + 1
|
||||||
|
w.Header().Set("Retry-After", strconv.Itoa(after))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user