-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/formatter_adding_variables'
- Loading branch information
Showing
27 changed files
with
696 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package body_record_truncation | ||
|
||
type Config struct { | ||
BodySize int64 `json:"body_size" label:"截断大小"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package body_record_truncation | ||
|
||
import ( | ||
"github.com/eolinker/apinto/drivers" | ||
"github.com/eolinker/eosc" | ||
"github.com/eolinker/eosc/eocontext" | ||
http_service "github.com/eolinker/eosc/eocontext/http-context" | ||
) | ||
|
||
var () | ||
|
||
var _ http_service.HttpFilter = (*executor)(nil) | ||
var _ eocontext.IFilter = (*executor)(nil) | ||
var _ eosc.IWorker = (*executor)(nil) | ||
|
||
type executor struct { | ||
drivers.WorkerBase | ||
bodySize int64 | ||
} | ||
|
||
func (e *executor) DoFilter(ctx eocontext.EoContext, next eocontext.IChain) (err error) { | ||
return http_service.DoHttpFilter(e, ctx, next) | ||
} | ||
|
||
func (e *executor) DoHttpFilter(ctx http_service.IHttpContext, next eocontext.IChain) (err error) { | ||
if ctx.Request().Method() == "POST" || ctx.Request().Method() == "PUT" || ctx.Request().Method() == "PATCH" { | ||
if e.bodySize != 0 && int64(ctx.Request().ContentLength()) > e.bodySize { | ||
// 当请求体大小大于限制时,截断请求体 | ||
entry := ctx.GetEntry() | ||
body := entry.Read("ctx_request_body") | ||
v, _ := body.(string) | ||
ctx.SetLabel("request_body", v[:e.bodySize]) | ||
ctx.WithValue("request_body_complete", 0) | ||
} else { | ||
ctx.WithValue("request_body_complete", 1) | ||
} | ||
} | ||
if next != nil { | ||
err = next.DoChain(ctx) | ||
} | ||
if e.bodySize != 0 && int64(ctx.Response().ContentLength()) > e.bodySize { | ||
// 当响应体大小大于限制时,截断响应体 | ||
entry := ctx.GetEntry() | ||
body := entry.Read("ctx_response_body") | ||
v, _ := body.(string) | ||
ctx.SetLabel("response_body", v[:e.bodySize]) | ||
ctx.WithValue("response_body_complete", 0) | ||
} else { | ||
ctx.WithValue("response_body_complete", 1) | ||
} | ||
return err | ||
} | ||
|
||
func (e *executor) Destroy() { | ||
return | ||
} | ||
|
||
func (e *executor) Start() error { | ||
return nil | ||
} | ||
|
||
func (e *executor) Reset(conf interface{}, workers map[eosc.RequireId]eosc.IWorker) error { | ||
return nil | ||
} | ||
|
||
func (e *executor) Stop() error { | ||
e.Destroy() | ||
return nil | ||
} | ||
|
||
func (e *executor) CheckSkill(skill string) bool { | ||
return http_service.FilterSkillName == skill | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package body_record_truncation | ||
|
||
import ( | ||
"github.com/eolinker/apinto/drivers" | ||
"github.com/eolinker/eosc" | ||
) | ||
|
||
const ( | ||
Name = "body-record-truncation" | ||
) | ||
|
||
func Register(register eosc.IExtenderDriverRegister) { | ||
register.RegisterExtenderDriver(Name, NewFactory()) | ||
} | ||
|
||
func NewFactory() eosc.IExtenderDriverFactory { | ||
return drivers.NewFactory[Config](Create) | ||
} | ||
|
||
func Create(id, name string, conf *Config, workers map[eosc.RequireId]eosc.IWorker) (eosc.IWorker, error) { | ||
|
||
return &executor{ | ||
WorkerBase: drivers.Worker(id, name), | ||
bodySize: conf.BodySize << 20, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package request_file_parse | ||
|
||
type Config struct { | ||
FileKey string `json:"file_key" label:"文件Key"` | ||
FileSuffix []string `json:"file_suffix" label:"文件有效后缀列表"` | ||
LargeWarn int64 `json:"large_warn" label:"文件大小警告阈值"` | ||
LargeWarnText string `json:"large_warn_text" label:"文件大小警告标签值"` | ||
} |
Oops, something went wrong.