-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Introduce flag constants and enable conditional caching of erro… #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -387,13 +387,21 @@ func (c *Caching) doProxy(req *http.Request, subRequest bool) (*http.Response, e | |||||||||||||||
| c.md.Size = respRange.ObjSize | ||||||||||||||||
|
|
||||||||||||||||
| // error code cache feature. | ||||||||||||||||
| if statusCode >= http.StatusBadRequest && | ||||||||||||||||
| resp.Header.Get(constants.InternalCacheErrCode) != "1" { | ||||||||||||||||
| c.cacheable = false // 禁止缓存错误码缓存 | ||||||||||||||||
|
|
||||||||||||||||
| copiedHeaders := make(http.Header) | ||||||||||||||||
| xhttp.CopyHeader(copiedHeaders, resp.Header) | ||||||||||||||||
| c.md.Headers = copiedHeaders | ||||||||||||||||
| if statusCode >= http.StatusBadRequest { | ||||||||||||||||
|
|
||||||||||||||||
| // Caching is disabled | ||||||||||||||||
| // restoring the default behavior for error codes. | ||||||||||||||||
| if resp.Header.Get(constants.InternalCacheErrCode) != constants.FlagOn { | ||||||||||||||||
| c.cacheable = false | ||||||||||||||||
|
|
||||||||||||||||
| copiedHeaders := make(http.Header) | ||||||||||||||||
| xhttp.CopyHeader(copiedHeaders, resp.Header) | ||||||||||||||||
| c.md.Headers = copiedHeaders | ||||||||||||||||
| } else { | ||||||||||||||||
| // Caching is allowed (or rather, not disabled), | ||||||||||||||||
| // and the proxy error is suppressed | ||||||||||||||||
| proxyErr = nil | ||||||||||||||||
|
||||||||||||||||
| proxyErr = nil | |
| proxyErr = nil | |
| // Ensure metadata headers are updated for cached error responses. | |
| copiedHeaders := make(http.Header) | |
| xhttp.CopyHeader(copiedHeaders, resp.Header) | |
| c.md.Headers = copiedHeaders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FlagOn/FlagOffare very generic exported names in a sharedconstantspackage, which makes it unclear what they apply to and increases the chance of future collisions/ambiguity. Consider using more specific names (e.g.,GatewayFlagOn/GatewayFlagOfforControlFlagOn/ControlFlagOff, or even feature-scoped constants likeCacheErrCodeFlagOn).