refactor(server): replace rawHTTPResponseWriter with stdlib http.Server
- Rewrite server to use net/http.Server with ServeHTTP handler instead of raw TCP listener with hand-written HTTP responses. Control plane errors now get proper Content-Type, Content-Length, and chunked encoding via http.Error(). Tunnel traffic hijacks the connection and re-serializes the request for forwarding. - Simplify reconstructedConn to accept variative io.Readers - Delete raw_http_response_writer.go (no longer needed) - Fix TCP forwarder: bare host:port (e.g. "127.0.0.1:5432") now works correctly instead of failing on url.Parse. Only HTTP/HTTPS schemes go through URL parsing; everything else is treated as raw TCP. - Add 8 new e2e tests: HTTP response quality, 1MB response body, 512KB request body, TCP echo, TCP large payload, concurrent single-tunnel, concurrent multi-tunnel (16 tests total, all passing)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
@@ -14,17 +13,17 @@ type reconstructedConn struct {
|
||||
reader io.Reader
|
||||
}
|
||||
|
||||
// Read reads from the reconstructed reader (captured data + original conn).
|
||||
// Read reads from the reconstructed reader (prepended data + original conn).
|
||||
func (rc *reconstructedConn) Read(p []byte) (n int, err error) {
|
||||
return rc.reader.Read(p)
|
||||
}
|
||||
|
||||
// newReconstructedConn creates a reconstructed connection that replays captured data
|
||||
// before reading from the original connection.
|
||||
func newReconstructedConn(conn net.Conn, capturedData *bytes.Buffer) net.Conn {
|
||||
allReader := io.MultiReader(capturedData, conn)
|
||||
// newReconstructedConn creates a reconstructed connection that replays the provided
|
||||
// readers in order before reading from the underlying connection.
|
||||
func newReconstructedConn(conn net.Conn, readers ...io.Reader) net.Conn {
|
||||
allReaders := append(readers, conn)
|
||||
return &reconstructedConn{
|
||||
Conn: conn,
|
||||
reader: allReader,
|
||||
reader: io.MultiReader(allReaders...),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user