mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 00:59:11 +01:00
* chore(deps): update submodule goutils * docs(http): remove default client from README.md * refactor(rules): introduce block DSL, phase-based execution, and flow validation - add block syntax parser/scanner with nested @blocks and elif/else support - restructure rule execution into explicit pre/post phases with phase flags - classify commands by phase and termination behavior - enforce flow semantics (default rule handling, dead-rule detection) - expand HTTP flow coverage with block + YAML parity tests and benches - refresh rules README/spec and update playground/docs integration - Default rules act as fallback handlers that execute only when no matching non-default rule exists in the pre phase - IfElseBlockCommand now returns early when a condition matches with a nil Do block, instead of falling through to else blocks - Add nil check for auth handler to allow requests when no auth is configured * fix(rules): buffer log output before writing to stdout/stderr * refactor(api/rules): remove IsResponseRule field from ParsedRule and related logic * docs(rules): update examples to use block syntax
32 lines
1.3 KiB
Go
32 lines
1.3 KiB
Go
package rules
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
httputils "github.com/yusing/goutils/http"
|
|
)
|
|
|
|
func BenchmarkExpandVars(b *testing.B) {
|
|
testResponseModifier := httputils.NewResponseModifier(httptest.NewRecorder())
|
|
testResponseModifier.WriteHeader(http.StatusOK)
|
|
testResponseModifier.Write([]byte("Hello, world!"))
|
|
testRequest := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
testRequest.Header.Set("User-Agent", "test-agent/1.0")
|
|
testRequest.Header.Set("X-Custom", "value1,value2")
|
|
testRequest.ContentLength = 12345
|
|
testRequest.RemoteAddr = "192.168.1.100:54321"
|
|
testRequest.Form = url.Values{"param1": {"value1"}, "param2": {"value2"}}
|
|
testRequest.PostForm = url.Values{"param3": {"value3"}, "param4": {"value4"}}
|
|
|
|
for b.Loop() {
|
|
_, err := ExpandVars(testResponseModifier, testRequest, "$req_method $req_path $req_query $req_url $req_uri $req_host $req_port $req_addr $req_content_type $req_content_length $remote_host $remote_port $remote_addr $status_code $resp_content_type $resp_content_length $header(User-Agent) $header(X-Custom, 0) $header(X-Custom, 1) $arg(param1) $arg(param2) $arg(param3) $arg(param4) $form(param1) $form(param2) $form(param3) $form(param4) $postform(param1) $postform(param2) $postform(param3) $postform(param4)", io.Discard)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|