Commit 3db598b
refactor(proxy): complete tls-client migration with fixes and tests
The migration to tls-client (commit c6ee11d) introduced direct fhttp
dependencies. These changes complete the migration:
Bug fixes:
- Replace naive prefix-matching in dumbResponseWriter with state-aware
CONNECT header handling. The old code swallowed any "HTTP/1.0 200"
prefix, including in response bodies. New approach tracks WriteHeader
state to correctly swallow only the CONNECT OK header.
- Remove TOCTOU-prone RWMutex double-check pattern in TransportCache.
The old RLock/RUnlock then Lock double-check had a race window
between lock upgrade calls.
New features:
- Graceful HTTPS connection draining on shutdown using sync.WaitGroup.
Active connections are tracked and waited on (with 10s timeout).
TCP listener is closed immediately on shutdown signal.
- Add client remote address to non-SNI warning for better diagnostics.
Code quality:
- Simplify fingerprintRoundTripperWrapper to pass ctx.Req directly
instead of creating a request copy via WithContext.
- Add comprehensive unit tests for net/http <-> fhttp conversion layer.
- Rewrite dumbResponseWriter tests with proper subtests (fragmented
headers, 502 error passthrough, post-CONNECT data passthrough).
- Improve mockConn test helper with proper write buffer tracking.
Co-authored-by: CommandCodeBot <noreply@commandcode.ai>1 parent b3a7e8c commit 3db598b
2 files changed
Lines changed: 283 additions & 79 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 89 | | |
103 | 90 | | |
104 | 91 | | |
105 | | - | |
106 | 92 | | |
107 | 93 | | |
108 | 94 | | |
109 | 95 | | |
110 | 96 | | |
111 | | - | |
112 | 97 | | |
113 | 98 | | |
114 | 99 | | |
| |||
243 | 228 | | |
244 | 229 | | |
245 | 230 | | |
246 | | - | |
247 | | - | |
248 | | - | |
| 231 | + | |
249 | 232 | | |
250 | 233 | | |
251 | 234 | | |
| |||
349 | 332 | | |
350 | 333 | | |
351 | 334 | | |
| 335 | + | |
352 | 336 | | |
353 | 337 | | |
354 | 338 | | |
| |||
471 | 455 | | |
472 | 456 | | |
473 | 457 | | |
474 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
475 | 463 | | |
476 | 464 | | |
477 | 465 | | |
478 | 466 | | |
479 | 467 | | |
480 | 468 | | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
481 | 483 | | |
482 | 484 | | |
483 | 485 | | |
| |||
504 | 506 | | |
505 | 507 | | |
506 | 508 | | |
507 | | - | |
| 509 | + | |
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
| |||
525 | 527 | | |
526 | 528 | | |
527 | 529 | | |
528 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
529 | 535 | | |
530 | 536 | | |
531 | 537 | | |
| |||
536 | 542 | | |
537 | 543 | | |
538 | 544 | | |
539 | | - | |
540 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
541 | 555 | | |
542 | | - | |
| 556 | + | |
543 | 557 | | |
544 | 558 | | |
545 | 559 | | |
546 | | - | |
| 560 | + | |
| 561 | + | |
547 | 562 | | |
548 | 563 | | |
549 | 564 | | |
| |||
0 commit comments