Skip to content

Commit 155a5d3

Browse files
committed
Fixed using --http3 with --connect-to
1 parent 89e5543 commit 155a5d3

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ adheres to [Semantic Versioning][semver].
1313

1414
### Fixed
1515

16+
- Fixed using `--http3` together with `--connect-to`.
1617
- Fixed unexpected panic when the server stops responding unexpectedly.
1718

1819
[unreleased]: https://github.com/ameshkov/gocurl/compare/v1.5.0...HEAD

internal/client/clientdialer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ func (d *clientDialer) DialQUIC(
105105
return nil, fmt.Errorf("dialer returned not a PacketConn for %s", addr)
106106
}
107107

108-
udpAddr, err := net.ResolveUDPAddr("udp", addr)
109-
if err != nil {
110-
return nil, err
108+
udpAddr, ok := conn.RemoteAddr().(*net.UDPAddr)
109+
if !ok {
110+
return nil, fmt.Errorf("dialer returned not a UDPAddr for %s", addr)
111111
}
112112

113113
return quic.DialEarly(ctx, uConn, udpAddr, d.tlsConfig, cfg)

internal/cmd/cmd_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,53 @@ func TestRunWithHTTP3(t *testing.T) {
656656
assert.Contains(t, data, "HTTP/3 test response", "Response should contain HTTP/3 test data")
657657
}
658658

659+
// TestRunWithHTTP3AndConnectTo tests the --http3 flag combined with --connect-to.
660+
func TestRunWithHTTP3AndConnectTo(t *testing.T) {
661+
// Create an HTTP/3 test server (our actual target)
662+
h3Server, serverAddr := createTestHTTP3Server(t)
663+
defer func() {
664+
_ = h3Server.Close()
665+
}()
666+
667+
// Create buffers for output
668+
dataBuffer := &bytes.Buffer{}
669+
logBuffer := &bytes.Buffer{}
670+
671+
// Create a fake hostname that will be redirected to the real server
672+
fakeHost := "fake-http3.example.com:443"
673+
674+
// Parse config with --http3 and --connect-to arguments
675+
// Format: HOST1:PORT1:HOST2:PORT2
676+
// We redirect fake-http3.example.com:443 to the actual test server
677+
connectToValue := fmt.Sprintf("fake-http3.example.com:443:%s", serverAddr)
678+
args := []string{
679+
"--http3",
680+
"--insecure",
681+
"--connect-to", connectToValue,
682+
"https://fake-http3.example.com:443/get",
683+
}
684+
cfg, err := config.ParseConfig(args)
685+
require.NoError(t, err)
686+
687+
// Verify the connect-to mapping was parsed correctly
688+
require.NotNil(t, cfg.ConnectTo)
689+
require.Equal(t, serverAddr, cfg.ConnectTo[fakeHost])
690+
691+
// Verify that ForceHTTP3 is set to true
692+
assert.True(t, cfg.ForceHTTP3, "ForceHTTP3 should be set to true when --http3 flag is used")
693+
694+
// Create output with mock writers
695+
out := output.NewOutputWithWriters(dataBuffer, logBuffer, cfg.Verbose, cfg.OutputJSON)
696+
697+
// Run the command
698+
err = cmd.Run(cfg, out)
699+
require.NoError(t, err)
700+
701+
// If the request succeeded (connect-to worked), verify the output
702+
data := dataBuffer.String()
703+
assert.Contains(t, data, "HTTP/3 test response", "Response should contain HTTP/3 test data")
704+
}
705+
659706
// createTestProxy creates a test HTTP CONNECT proxy server that tracks requests.
660707
// Returns the proxy server and a pointer to a boolean that indicates if the proxy
661708
// received a request.

0 commit comments

Comments
 (0)