Skip to content

Commit 2eb98ff

Browse files
committed
fix: added some hostname header magic if port is given in server address, --hostname is not needed anymore per default
1 parent f5feed9 commit 2eb98ff

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

main.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"flag"
55
"fmt"
66
"log"
7+
"net"
78
"net/http"
9+
"net/url"
810
"os"
911
"runtime"
1012
"strconv"
@@ -118,8 +120,9 @@ var serverHelp = `
118120
--keyfile, An optional path to a PEM-encoded SSH private key. When
119121
this flag is set, the --key option is ignored, and the provided private key
120122
is used to secure all communications. (defaults to the CHISEL_KEY_FILE
121-
environment variable). Since ECDSA keys are short, you may also set keyfile
122-
to an inline base64 private key (e.g. chisel server --keygen - | base64).
123+
environment variable). Since ECDSA keys are short, you may also supply
124+
the chiselkey (output of "chisel server --keygen -") as the argument
125+
to --keyfile and forgo requiring a file on disk.
123126
124127
--authfile, An optional path to a users.json file. This file should
125128
be an object with users defined like:
@@ -454,10 +457,26 @@ func client(args []string) {
454457
if config.Auth == "" {
455458
config.Auth = os.Getenv("AUTH")
456459
}
457-
//move hostname onto headers
460+
461+
Hostname := ""
462+
//set via --hostname
458463
if *hostname != "" {
459-
config.Headers.Set("Host", *hostname)
460-
config.TLS.ServerName = *hostname
464+
Hostname = *hostname
465+
} else {
466+
//not set via --hostname but ':' in Server, we need to set Header without Port or connection will fail
467+
u, err := url.Parse(config.Server)
468+
if err == nil {
469+
host, port, _ := net.SplitHostPort(u.Host)
470+
if port != "" {
471+
Hostname = host
472+
}
473+
}
474+
}
475+
476+
//move hostname onto headers
477+
if Hostname != "" {
478+
config.Headers.Set("Host", Hostname)
479+
config.TLS.ServerName = Hostname
461480
}
462481

463482
if *sni != "" {

0 commit comments

Comments
 (0)