651 Commits

Author SHA1 Message Date
xfy911
4a53d3032a docs(utils): add package comments for utils module
- Add package documentation for internal, etag, and bytes files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
c33adeb296 docs(middleware/limitrate): add package comments for rate limiter
- Add package documentation for limitrate and writer files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
05f434d5e5 docs(server): add package comments for server module
- Add package documentation for router, internal, lifecycle, and middleware_builder files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
dc54d3822f docs(proxy): add package comments for proxy module
- Add package documentation for target_selector, utils, validate,
  cache_handler, and header_modifier files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
65aaba4e59 docs(config): add package comments for config module
- Add package documentation for cache, monitoring, performance, proxy,
  security, server, ssl, and variable config files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy
863456f7b4 chore: add docs/superpowers to gitignore
Ignore agent-generated planning and specification documents.
2026-06-03 14:41:27 +08:00
xfy
8ae4add922 fix: address code review feedback
- proxyDebugLog: move Enabled() guard to call sites to avoid allocations
- proxyDebugLog: add default case for unsupported types
- static routes: remove unintended regex support to match original behavior
2026-06-03 14:29:30 +08:00
xfy
4678cb5483 refactor: use testutil helpers in server tests 2026-06-03 14:19:22 +08:00
xfy
8681472c4b refactor: use testutil helpers in proxy tests 2026-06-03 14:10:07 +08:00
xfy
094976df2b feat: add testutil package for proxy config helpers 2026-06-03 14:00:07 +08:00
xfy
1ce42c039b refactor: extract proxyDebugLog helper for repeated debug logging 2026-06-03 13:57:55 +08:00
xfy
684122dbf7 refactor: extract registerRoute helper to reduce repetition 2026-06-03 13:55:18 +08:00
xfy
37e20ae9a0 refactor: remove unused extractCertificates function and tests 2026-06-03 13:51:55 +08:00
xfy
bc0bc5fbbb refactor: remove unused security header preset functions and tests 2026-06-03 13:49:57 +08:00
xfy
e3c6cb61f0 refactor: remove unused bodylimit.formatSize function and test 2026-06-03 13:48:10 +08:00
xfy
596237e484 refactor: remove unused connectionPool.get and connectionPool.count methods 2026-06-03 13:46:25 +08:00
xfy
caae75ff96 refactor: remove unused validateStatic function and its test 2026-06-03 13:44:22 +08:00
634fc5b51b
Merge pull request #2 from DefectingCat/fix/identified-issues
fix/identified issues
2026-06-03 13:24:15 +08:00
xfy
728a9f454b fix(server,app,config): address code review findings
- Fix FD leak in DupListener: close *os.File after net.FileListener
- Add cleanup of partially-duped listeners on DupListener failure
- Make reload timeout configurable via shutdown.reload_timeout
- Handle filepath.Abs errors in processIncludes instead of ignoring
- Use net.ParseIP in isAnyAddr for robust IPv6 support
2026-06-03 13:16:05 +08:00
xfy
9b8ce2a08a fix(config): real circular include detection with visited set
Replace depth-only detection with path-based visited set tracking.
Detects cycles immediately on first revisit instead of after 10 depth
iterations. Supports diamond patterns (A->B->shared, A->C->shared)
via backtracking. Add self-include and diamond tests. Document that
only servers/stream/variables are merged in defaults.go.
2026-06-03 11:51:17 +08:00
xfy
556d40ceb0 fix(matcher,server): use ConflictError in AddNamed and add tests
Make AddNamed return *ConflictError for consistency with other Add*
methods so handleRegistrationError treats named location conflicts as
warnings instead of fatal errors. Add tests for handleRegistrationError
covering both conflict and fatal error paths.
2026-06-03 11:47:06 +08:00
xfy
f58f194752 fix(server): serialize listener creation in multi-server mode
Remove VHost fallback during graceful upgrade. Serialize listener
creation before parallel router/middleware setup to prevent concurrent
inherited listener consumption. Fix tcpAddrMatch to match when either
side is any-addr (0.0.0.0/::).
2026-06-03 11:44:14 +08:00
xfy
f3f78b24a8 feat(server,app): implement proper config hot reload via SIGHUP
createListener now checks pre-set s.listeners (Path 2) for hot reload,
not just upgradeManager.IsChild() (Path 1). Add DupListener to dup FDs
so old/new servers own independent listeners. Reload rebuilds HTTP/2
and HTTP/3. Add matchInheritedListener with TCP any-addr matching.
Add requiresFullRestart with VHost server count detection.
2026-06-03 11:42:45 +08:00
xfy
2e9ddc7400 feat(config): implement include directive with glob support
Support loading config fragments from external files via include
directive. Servers and streams are appended, variables merged with
main config priority. Includes glob expansion, nested includes
(depth limit 10), and circular include detection.
2026-06-03 10:20:33 +08:00
xfy
53ac4c84cd docs(AGENTS.md): fix stale references
Remove non-existent config.example.yaml and .github/ directory
references. Add --generate-config usage note.
2026-06-03 10:16:29 +08:00
xfy
d9a7ab9cca cleanup(config): remove dead ProxyCachePathConfig and CachePath field
Disk cache implementation was previously removed but config structs
remained. Remove ProxyCachePathConfig, Config.CachePath field, e2e
WithCachePath helper, and docs reference.
2026-06-03 10:14:07 +08:00
xfy
38bb743781 fix(server): handle LocationEngine registration errors properly
Add typed ConflictError for path conflicts, change register functions
to return errors, handle conflicts as warnings and fatal errors as
startup failures. Remove all 20 instances of ignored Add* return values.
2026-06-03 10:12:09 +08:00
xfy
ac66ea5534 fix(server): use atomic.Bool for Server.running to eliminate data race
Server.running was a plain bool accessed from multiple goroutines
(start/stop/signal handlers). Convert to atomic.Bool with
Store/Load to make all accesses safe for concurrent use.

Updates all test files to use the new atomic API.
2026-06-03 01:19:23 +08:00
xfy
0359d4c477 fix(stream): use atomic operations for counters and fix UDP conns leak
- Server.connCount and Target.conns now use atomic.AddInt64/LoadInt64
  instead of non-atomic ++ and --, fixing data races under concurrency
- UDP sessions now store a reference to their target and decrement
  target.conns in close(), preventing monotonically increasing counts
  that would break least_conn load balancing over time
2026-06-03 01:16:37 +08:00
xfy
eb404f98a2 fix(ssl): implement OCSP refreshAll to actually refresh stale responses
refreshAll() was a no-op — it checked which entries needed refreshing
but never called fetchOCSP. Now it:
- Stores cert/issuer pairs when registering certificates
- Actually fetches fresh OCSP responses for stale/expired entries
- Updates error counts and marks entries as failed after max retries
2026-06-03 01:14:09 +08:00
xfy
3b84d62971 fix(ssl): extract OCSP HTTP request loop into singleOCSPAttempt
The previous code used defer resp.Body.Close() inside a for loop,
causing all response bodies to remain open until the function returned.
Extract the per-attempt logic into singleOCSPAttempt so each response
body is closed immediately after processing.
2026-06-03 01:11:07 +08:00
xfy
f6c1ee8180 fix(proxy): log error when upstream TLS config creation fails
Previously the error was silently swallowed, causing the proxy to
fall back to default TLS settings (no custom CA, no mTLS, no SNI)
without any indication. Now the error is logged at ERROR level.
2026-06-03 01:09:40 +08:00
xfy
2c3cc1ba38 fix(proxy): prevent use-after-recycle in background cache refresh
Copy the request before spawning the background goroutine. The
fasthttp.RequestCtx is recycled after the handler returns, so passing
it to a goroutine causes data corruption under high concurrency.

The caller now AcquireRequest+CopyTo before go(), and the goroutine
releases it. backgroundRefresh no longer accepts ctx directly.
2026-06-03 01:08:50 +08:00
xfy
c2dd4fa9a3 fix(resolver): prevent double-close panic in DNSResolver.Stop()
Use atomic Swap instead of Load+close+Store to eliminate the race
window where concurrent Stop() calls could both pass the check.
2026-06-03 01:07:54 +08:00
xfy
ba0b3c55bb fix(loadbalance): prevent double-close panic in SlowStartManager.Stop()
Use atomic Swap instead of Load+close to prevent concurrent Stop()
calls from both passing the check and closing the channel twice.
2026-06-03 01:07:22 +08:00
xfy
332b96031b docs: simplify README.md to focus on project introduction
Remove all example code, installation commands, configuration samples,
Lua script examples, Docker deployment, benchmark data, and troubleshooting
sections. Keep only core feature descriptions, architecture overview, and
dependency list.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 18:22:30 +08:00
xfy
b2ae4472d7 refactor(gjson): remove nolint comment from cfgEncodeSortKeys
The nolint:unused comment added in c47ab16 is no longer needed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 18:14:41 +08:00
xfy
b6018ff9c9 test: add t.Parallel() to enable parallel test execution
Add t.Parallel() to 110 test functions across 3 test files:
- internal/loadbalance/balancer_test.go (42 tests)
- internal/config/validate_test.go (21 tests)
- internal/server/status_test.go (47 tests)

This reduces total test time from ~3 minutes to ~34 seconds (5.4x faster).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:57:23 +08:00
xfy
c47ab1617f fix(gjson): add nolint comment for cfgEncodeSortKeys method
The method is registered to Lua via instance.cfgEncodeSortKeys pattern,
which the linter cannot detect.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:38:09 +08:00
xfy
c37364b309 style: format code and modernize loop syntax
- Align struct fields and constants in gjson/config.go
- Add missing newline at EOF in gjson/decode.go
- Remove trailing blank line in gjson/encode.go
- Remove extra blank line in internal/lua/coroutine.go
- Use modern for range syntax in internal/lua/pool.go

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:34:59 +08:00
xfy
8643a0aff9 refactor: improve error handling and fix linter warnings
- Add nolint comments for type assertion errcheck in gjson/encode.go
  (switch case guarantees type safety)
- Handle fasthttp.Serve errors in benchmark mock backends
- Rename error variables to avoid shadowing in server.go
- Use underscore for unused loop variables

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:32:06 +08:00
xfy
c157be1ce5 refactor(cache): remove unused disk/tiered cache and add helper functions
Remove unused disk cache, tiered cache, purge, and config loader code.
Add HashPathWithMethod and MatchPattern helpers for future cache purge API.
Update test to use new mock backend API with ResponseBody field.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:26:19 +08:00
xfy
25d93c25fa refactor: remove unused code and fix formatting
- Remove unused benchmark/tools package
- Make ValidAlgorithms private (validAlgorithms) in loadbalance
- Remove dead code (_ = result) in lua/api_socket_tcp.go
- Fix code formatting with goimports

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 16:58:45 +08:00
xfy
ce80352e79 feat(gjson): add encode_sort_keys option for stable JSON output
Add configurable key sorting for JSON object encoding. When enabled,
object keys are sorted alphabetically for deterministic output.
Default is disabled for better performance.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 16:09:49 +08:00
xfy
62be8bc557 feat(lua): enable package library and preload gjson module
Add glua.OpenPackage for require support and preload gjson module
to make JSON encoding/decoding available in Lua scripts.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 15:51:26 +08:00
xfy
376b9fd33c feat(gjson): add Lua JSON encoding/decoding library
Add gjson package providing high-performance JSON encoding/decoding
for gopher-lua with lua-cjson API compatibility. Uses goccy/go-json
as the underlying JSON engine.

Features:
- Full lua-cjson API compatibility for OpenResty migration
- Sparse array detection and handling
- Maximum nesting depth control for encode/decode
- Number precision control
- Independent configuration instances via gjson.new()
- gjson.null sentinel for JSON null values

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 15:44:31 +08:00
xfy
81df41b817 docs: update code statistics and simplify README structure
- Update stats: 234 source files, 242 test files, ~189K lines, 81.3% coverage
- Remove GeoIP filter from feature list
- Simplify directory structure section
- Remove redundant diagrams and detailed module breakdowns
- Streamline monitoring and deployment sections

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 15:36:39 +08:00
xfy
9c091e528b docs(lua): add route script documentation and examples
- Add route script vs middleware script distinction
- Document route_type options (exact, prefix, regex, etc.)
- Add practical examples: status, health, echo, ip, json, redirect
- Document enable_file_watch for hot reload support

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 13:57:33 +08:00
xfy
986ebdf207 fix(lua): enable file watch by default for hot reload
EnableFileWatch was false by default (Go bool zero value) when
global_settings was not configured. Now defaults to true to enable
Lua script hot reload without server restart.

Also fix indentation in init.go default value settings.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 13:45:55 +08:00
xfy
8f3c304837 fix(lua): register Lua routes in multi-server mode
Add registerLuaRoutes method for router-based route registration
and call it in startMultiServerMode to fix Lua routes not working
when multiple servers are configured.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 13:41:26 +08:00