Files
conduit/tunnel/forwarder.go
Evan Reichard 7df8521478 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)
2026-05-03 22:41:57 -04:00

36 lines
745 B
Go

package tunnel
import (
"context"
"net/url"
"reichard.io/conduit/store"
)
type ForwarderType int
const (
ForwarderTCP ForwarderType = iota
ForwarderHTTP
)
type Forwarder interface {
Type() ForwarderType
Initialize(sourceAddress string) (Stream, error)
Start(context.Context) error
}
func NewForwarder(target string, tunnelStore store.TunnelStore) (Forwarder, error) {
// Only parse as URL for HTTP targets. Bare host:port (e.g., "127.0.0.1:5432")
// is not a valid URL and should be treated as a raw TCP target.
targetURL, err := url.Parse(target)
if err == nil {
switch targetURL.Scheme {
case "http", "https":
return newHTTPForwarder(targetURL, tunnelStore)
}
}
return newTCPForwarder(target, tunnelStore), nil
}