mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 04:37:31 +08:00
make the wasm-go lib easier to use (#58)
This commit is contained in:
@@ -31,7 +31,7 @@ func main() {
|
||||
type HelloWorldConfig struct {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx *wrapper.CommonHttpCtx[HelloWorldConfig], config HelloWorldConfig, needBody *bool, log wrapper.LogWrapper) types.Action {
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config HelloWorldConfig, log wrapper.Log) types.Action {
|
||||
err := proxywasm.AddHttpRequestHeader("hello", "world")
|
||||
if err != nil {
|
||||
log.Critical("failed to set request header")
|
||||
|
||||
@@ -41,7 +41,7 @@ type HttpCallConfig struct {
|
||||
tokenHeader string
|
||||
}
|
||||
|
||||
func parseConfig(json gjson.Result, config *HttpCallConfig, log wrapper.LogWrapper) error {
|
||||
func parseConfig(json gjson.Result, config *HttpCallConfig, log wrapper.Log) error {
|
||||
config.bodyHeader = json.Get("bodyHeader").String()
|
||||
if config.bodyHeader == "" {
|
||||
return errors.New("missing bodyHeader in config")
|
||||
@@ -96,7 +96,7 @@ func parseConfig(json gjson.Result, config *HttpCallConfig, log wrapper.LogWrapp
|
||||
}
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx *wrapper.CommonHttpCtx[HttpCallConfig], config HttpCallConfig, needBody *bool, log wrapper.LogWrapper) types.Action {
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config HttpCallConfig, log wrapper.Log) types.Action {
|
||||
config.client.Get(config.requestPath, nil,
|
||||
func(statusCode int, responseHeaders http.Header, responseBody []byte) {
|
||||
defer proxywasm.ResumeHttpRequest()
|
||||
|
||||
@@ -44,7 +44,7 @@ type RequestBlockConfig struct {
|
||||
blockBodys []string
|
||||
}
|
||||
|
||||
func parseConfig(json gjson.Result, config *RequestBlockConfig, log wrapper.LogWrapper) error {
|
||||
func parseConfig(json gjson.Result, config *RequestBlockConfig, log wrapper.Log) error {
|
||||
code := json.Get("blocked_code").Int()
|
||||
if code != 0 && code > 100 && code < 600 {
|
||||
config.blockedCode = uint32(code)
|
||||
@@ -93,7 +93,7 @@ func parseConfig(json gjson.Result, config *RequestBlockConfig, log wrapper.LogW
|
||||
return nil
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx *wrapper.CommonHttpCtx[RequestBlockConfig], config RequestBlockConfig, needBody *bool, log wrapper.LogWrapper) types.Action {
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config RequestBlockConfig, log wrapper.Log) types.Action {
|
||||
if len(config.blockUrls) > 0 {
|
||||
requestUrl, err := proxywasm.GetHttpRequestHeader(":path")
|
||||
if err != nil {
|
||||
@@ -132,12 +132,12 @@ func onHttpRequestHeaders(ctx *wrapper.CommonHttpCtx[RequestBlockConfig], config
|
||||
}
|
||||
}
|
||||
if len(config.blockBodys) == 0 {
|
||||
*needBody = false
|
||||
ctx.DontReadRequestBody()
|
||||
}
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
func onHttpRequestBody(ctx *wrapper.CommonHttpCtx[RequestBlockConfig], config RequestBlockConfig, body []byte, log wrapper.LogWrapper) types.Action {
|
||||
func onHttpRequestBody(ctx wrapper.HttpContext, config RequestBlockConfig, body []byte, log wrapper.Log) types.Action {
|
||||
bodyStr := string(body)
|
||||
if !config.caseSensitive {
|
||||
bodyStr = strings.ToLower(bodyStr)
|
||||
|
||||
Reference in New Issue
Block a user