Skip to content

Commit

Permalink
修改响应头部、请求头部返回值格式
Browse files Browse the repository at this point in the history
  • Loading branch information
Dot-Liu committed Nov 8, 2023
1 parent 41f7c59 commit 896aaa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions drivers/plugins/counter/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (b *executor) DoHttpFilter(ctx http_service.IHttpContext, next eocontext.IC
b.client = scope_manager.Auto[counter.IClient](b.clientID, "counter")
b.counterPusher = scope_manager.Auto[counter.ICountPusher](b.countPusherID, "counter-pusher")
})
body := ctx.Response().GetBody()
if len(body) < 1 {
return next.DoChain(ctx)
}

key := b.keyGenerate.Key(ctx)
ct, has := b.counters.Get(key)
Expand Down
16 changes: 14 additions & 2 deletions entries/http-entry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ var (
return ctx.Request().Header().GetHeader(strings.Replace(name, "_", "-", -1)), true
}),
"headers": ReadFunc(func(name string, ctx http_service.IHttpContext) (interface{}, bool) {
return ctx.Request().Header().Headers(), true
result := make(map[string]string)
for key, value := range ctx.Request().Header().Headers() {
result[strings.ToLower(key)] = strings.Join(value, ";")
}
return result, true
}),
"http": ReadFunc(func(name string, ctx http_service.IHttpContext) (interface{}, bool) {
return ctx.Request().Header().GetHeader(strings.Replace(name, "_", "-", -1)), true
Expand Down Expand Up @@ -220,7 +224,11 @@ var (
return ctx.Response().GetHeader(strings.Replace(name, "_", "-", -1)), true
}),
"headers": ReadFunc(func(name string, ctx http_service.IHttpContext) (interface{}, bool) {
return ctx.Response().Headers(), true
result := make(map[string]string)
for key, value := range ctx.Response().Headers() {
result[strings.ToLower(key)] = strings.Join(value, ";")
}
return result, true
}),
"status": ReadFunc(func(name string, ctx http_service.IHttpContext) (interface{}, bool) {
return ctx.Response().ProxyStatus(), true
Expand All @@ -233,6 +241,10 @@ var (
}),
},
"set_cookies": ReadFunc(func(name string, ctx http_service.IHttpContext) (interface{}, bool) {
cookies := ctx.Response().GetHeader("Set-Cookie")
if strings.TrimSpace(cookies) == "" {
return nil, true
}
return strings.Split(ctx.Response().GetHeader("Set-Cookie"), "; "), true
}),
"dst_ip": ReadFunc(func(name string, ctx http_service.IHttpContext) (interface{}, bool) {
Expand Down

0 comments on commit 896aaa2

Please sign in to comment.