From 2c62a1a1b47e15226a6781bda0521aa14256f755 Mon Sep 17 00:00:00 2001 From: Toby Date: Sun, 16 Jun 2024 13:26:02 -0700 Subject: [PATCH] fix: do not require client-side fast open --- core/internal/integration_tests/hook_test.go | 1 - core/server/server.go | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/internal/integration_tests/hook_test.go b/core/internal/integration_tests/hook_test.go index 14f67bc..43baf4f 100644 --- a/core/internal/integration_tests/hook_test.go +++ b/core/internal/integration_tests/hook_test.go @@ -57,7 +57,6 @@ func TestClientServerHookTCP(t *testing.T) { c, _, err := client.NewClient(&client.Config{ ServerAddr: udpAddr, TLSConfig: client.TLSConfig{InsecureSkipVerify: true}, - FastOpen: true, // Client MUST have FastOpen for this }) assert.NoError(t, err) defer c.Close() diff --git a/core/server/server.go b/core/server/server.go index 7ebb387..4fc9d41 100644 --- a/core/server/server.go +++ b/core/server/server.go @@ -214,9 +214,12 @@ func (h *h3sHandler) handleTCPRequest(stream quic.Stream) { // Call the hook if set var putback []byte if h.config.RequestHook != nil { + // When RequestHook is enabled, the server should always accept a connection + // so that the client will send whatever request the hook wants to see. + // This is essentially a server-side fast-open. + _ = protocol.WriteTCPResponse(stream, true, "RequestHook enabled") putback, err = h.config.RequestHook.TCP(stream, &reqAddr) if err != nil { - _ = protocol.WriteTCPResponse(stream, false, err.Error()) _ = stream.Close() return } @@ -228,7 +231,9 @@ func (h *h3sHandler) handleTCPRequest(stream quic.Stream) { // Dial target tConn, err := h.config.Outbound.TCP(reqAddr) if err != nil { - _ = protocol.WriteTCPResponse(stream, false, err.Error()) + if h.config.RequestHook == nil { + _ = protocol.WriteTCPResponse(stream, false, err.Error()) + } _ = stream.Close() // Log the error if h.config.EventLogger != nil { @@ -236,7 +241,9 @@ func (h *h3sHandler) handleTCPRequest(stream quic.Stream) { } return } - _ = protocol.WriteTCPResponse(stream, true, "") + if h.config.RequestHook == nil { + _ = protocol.WriteTCPResponse(stream, true, "Connected") + } // Put back the data if the hook requested if len(putback) > 0 { _, _ = tConn.Write(putback)