469 Commits

Author SHA1 Message Date
xfy
5066a1a64c feat(utils): add GetInternalRedirectPath function 2026-06-03 16:39:36 +08:00
xfy
1a6b5f9166 Merge origin/master into master 2026-06-03 16:36:23 +08:00
xfy
856b46fd6d refactor: remove unused ParseTLSVersion and app setter tests
- Remove sslutil.ParseTLSVersion (singular): unused, ParseTLSVersions (plural) is used
- Remove TestSetPidFile and TestSetLogFile: trivial setter tests
2026-06-03 16:32:15 +08:00
xfy
d0867bfe3e refactor(lua): remove unused mock engine and filter writer subsystem
- Delete mock_engine.go (331 lines): unused MockLuaEngine/MockCoroutine
- Delete filter_writer.go (811 lines): DelayedResponseWriter not integrated
- Delete filter_phase_test.go (1466 lines): tests for removed filter code
- Total: 2608 lines of dead code removed
2026-06-03 16:31:18 +08:00
xfy
2734b04d8f refactor: remove 16.8k lines of dead code across all internal packages
- Delete unused files: tempfile subsystem, matcher variants, server/internal
- Remove 200+ unused functions across proxy, ssl, lua, http2/3, stream, variable
- Fix proxy test type errors (backgroundRefresh ctx→Request)
- Move bench/tools mock backend into internal/testutil
- Remove corresponding test functions for all deleted code
2026-06-03 16:15:43 +08:00
5dec128510
Merge pull request #3 from xfy911/improve-comments
docs: add comprehensive documentation comments
2026-06-03 15:41:36 +08:00
xfy911
a6152d4dc1 docs: add documentation comments for method implementations and test utilities
- Add GoDoc for Warning.String, ParseError.Error
- Add GoDoc for ngxReqAPILayer.String, Phase.String, SocketState.String
- Add GoDoc for ConflictError.Error
- Add GoDoc for noopResolver methods (LookupHost, LookupHostWithCache, Refresh, Start, Stop, Stats)
- Add GoDoc for load balancer Select methods (roundRobin, weightedRoundRobin, ipHash)
- Add GoDoc for WithWSHeaders test utility
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
a136b07bb9 docs: add documentation comments for exported constants and variables
- Fix gjson/gjson.go package comments and constant documentation
- Fix internal/config/config.go constant documentation
- Fix internal/utils/httperror.go variable documentation
- Fix internal/matcher/matcher.go constant documentation
- Fix internal/middleware/compression/compression.go constant documentation
- Fix internal/middleware/limitrate/limitrate.go constant documentation
- Fix internal/middleware/rewrite/rewrite.go constant documentation
- Fix internal/middleware/security/access.go and auth.go constant documentation
- Fix internal/ssl/client_verify.go constant documentation
- Fix internal/variable/builtin.go and ssl.go constant documentation
- Fix internal/lua/api_log.go HTTP and log level constant documentation
- Fix internal/benchmark/tools/tools.go constant documentation
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
fc1de2d445 docs: add documentation comments for more exported constants and variables
- Add comments for ssl/client_verify.go verification modes
- Add comments for security/auth.go hash algorithms
- Add comments for rewrite/rewrite.go flags
- Add comments for compression/compression.go algorithms
- Add comments for limitrate/limitrate.go strategies
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
396a466de1 docs: add documentation comments for exported constants and variables
- Add comments for lua/api_log.go HTTP status codes and log levels
- Add comments for variable/builtin.go and ssl.go constants
- Add comments for utils/httperror.go error variables
- Add comments for matcher/matcher.go location types
- Add comments for compression/compression.go algorithms
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
0b5b0eb747 docs(loadbalance): add package comments for loadbalance module
- Add package documentation for random load balancing file
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
57d4d3ba3c docs(app): add package comments for app module
- Add package documentation for app, app_common, import, app_windows, and testutil files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
63ce8ecd2a docs(lua): add package comments for lua module
- Add package documentation for ip_guard file
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
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
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
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
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
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
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