mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 04:37:31 +08:00
feat: Add statusCodeDetails info when returning response in Wasm plugins directly (#1116)
This commit is contained in:
@@ -6,7 +6,7 @@ replace github.com/alibaba/higress/plugins/wasm-go => ../..
|
||||
|
||||
require (
|
||||
github.com/alibaba/higress/plugins/wasm-go v0.0.0
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240327114451-d6b7174a84fc
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240711023527-ba358c48772f
|
||||
github.com/tidwall/gjson v1.14.3
|
||||
github.com/zmap/go-iptree v0.0.0-20210731043055-d4e632617837
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240226064518-b3dc4646a35a h1
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240226064518-b3dc4646a35a/go.mod h1:hNFjhrLUIq+kJ9bOcs8QtiplSQ61GZXtd2xHKx4BYRo=
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240318034951-d5306e367c43/go.mod h1:hNFjhrLUIq+kJ9bOcs8QtiplSQ61GZXtd2xHKx4BYRo=
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240327114451-d6b7174a84fc/go.mod h1:hNFjhrLUIq+kJ9bOcs8QtiplSQ61GZXtd2xHKx4BYRo=
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20240711023527-ba358c48772f/go.mod h1:hNFjhrLUIq+kJ9bOcs8QtiplSQ61GZXtd2xHKx4BYRo=
|
||||
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
|
||||
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
||||
@@ -123,17 +123,17 @@ func getDownStreamIp(config RestrictionConfig) (net.IP, error) {
|
||||
func onHttpRequestHeaders(context wrapper.HttpContext, config RestrictionConfig, log wrapper.Log) types.Action {
|
||||
realIp, err := getDownStreamIp(config)
|
||||
if err != nil {
|
||||
return deniedUnauthorized(config)
|
||||
return deniedUnauthorized(config, "get_ip_failed")
|
||||
}
|
||||
allow := config.Allow
|
||||
deny := config.Deny
|
||||
if allow != nil {
|
||||
if realIp == nil {
|
||||
log.Error("realIp is nil, blocked")
|
||||
return deniedUnauthorized(config)
|
||||
return deniedUnauthorized(config, "empty_ip")
|
||||
}
|
||||
if _, found, _ := allow.Get(realIp); !found {
|
||||
return deniedUnauthorized(config)
|
||||
return deniedUnauthorized(config, "ip_not_allowed")
|
||||
}
|
||||
}
|
||||
if deny != nil {
|
||||
@@ -142,16 +142,16 @@ func onHttpRequestHeaders(context wrapper.HttpContext, config RestrictionConfig,
|
||||
return types.ActionContinue
|
||||
}
|
||||
if _, found, _ := deny.Get(realIp); found {
|
||||
return deniedUnauthorized(config)
|
||||
return deniedUnauthorized(config, "ip_denied")
|
||||
}
|
||||
}
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
func deniedUnauthorized(config RestrictionConfig) types.Action {
|
||||
func deniedUnauthorized(config RestrictionConfig, reason string) types.Action {
|
||||
body, _ := json.Marshal(map[string]string{
|
||||
"message": config.Message,
|
||||
})
|
||||
_ = proxywasm.SendHttpResponse(config.Status, nil, body, -1)
|
||||
_ = proxywasm.SendHttpResponseWithDetail(config.Status, "key-auth."+reason, nil, body, -1)
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user