mirror of
https://github.com/alibaba/higress.git
synced 2026-04-21 20:17:29 +08:00
ignore binary body in plugins (#711)
This commit is contained in:
@@ -263,6 +263,10 @@ func (ctx *CommonHttpCtx[PluginConfig]) OnHttpRequestHeaders(numHeaders int, end
|
|||||||
return types.ActionContinue
|
return types.ActionContinue
|
||||||
}
|
}
|
||||||
ctx.config = config
|
ctx.config = config
|
||||||
|
// To avoid unexpected operations, plugins do not read the binary content body
|
||||||
|
if IsBinaryRequestBody() {
|
||||||
|
ctx.needRequestBody = false
|
||||||
|
}
|
||||||
if ctx.plugin.vm.onHttpRequestHeaders == nil {
|
if ctx.plugin.vm.onHttpRequestHeaders == nil {
|
||||||
return types.ActionContinue
|
return types.ActionContinue
|
||||||
}
|
}
|
||||||
@@ -295,6 +299,10 @@ func (ctx *CommonHttpCtx[PluginConfig]) OnHttpResponseHeaders(numHeaders int, en
|
|||||||
if ctx.config == nil {
|
if ctx.config == nil {
|
||||||
return types.ActionContinue
|
return types.ActionContinue
|
||||||
}
|
}
|
||||||
|
// To avoid unexpected operations, plugins do not read the binary content body
|
||||||
|
if IsBinaryResponseBody() {
|
||||||
|
ctx.needResponseBody = false
|
||||||
|
}
|
||||||
if ctx.plugin.vm.onHttpResponseHeaders == nil {
|
if ctx.plugin.vm.onHttpResponseHeaders == nil {
|
||||||
return types.ActionContinue
|
return types.ActionContinue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,11 @@
|
|||||||
|
|
||||||
package wrapper
|
package wrapper
|
||||||
|
|
||||||
import "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
|
||||||
|
)
|
||||||
|
|
||||||
func GetRequestScheme() string {
|
func GetRequestScheme() string {
|
||||||
scheme, err := proxywasm.GetHttpRequestHeader(":scheme")
|
scheme, err := proxywasm.GetHttpRequestHeader(":scheme")
|
||||||
@@ -51,3 +55,29 @@ func GetRequestMethod() string {
|
|||||||
}
|
}
|
||||||
return method
|
return method
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsBinaryRequestBody() bool {
|
||||||
|
contentType, _ := proxywasm.GetHttpRequestHeader("content-type")
|
||||||
|
if strings.Contains(contentType, "octet-stream") ||
|
||||||
|
strings.Contains(contentType, "grpc") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
encoding, _ := proxywasm.GetHttpRequestHeader("content-encoding")
|
||||||
|
if encoding != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsBinaryResponseBody() bool {
|
||||||
|
contentType, _ := proxywasm.GetHttpResponseHeader("content-type")
|
||||||
|
if strings.Contains(contentType, "octet-stream") ||
|
||||||
|
strings.Contains(contentType, "grpc") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
encoding, _ := proxywasm.GetHttpResponseHeader("content-encoding")
|
||||||
|
if encoding != "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user