Browse Source

http2/h2i: add flag to dial one ip:port but SNI/:authority like it's another

Change-Id: I35049c37558ddedb9056278c9878f3e3fd6f7f76
Reviewed-on: https://go-review.googlesource.com/53640
Reviewed-by: Avelino <t@avelino.xxx>
Reviewed-by: Tom Bergan <tombergan@google.com>
Brad Fitzpatrick 8 years ago
parent
commit
167db312be
1 changed files with 6 additions and 2 deletions
  1. 6 2
      http2/h2i/h2i.go

+ 6 - 2
http2/h2i/h2i.go

@@ -45,6 +45,7 @@ var (
 	flagNextProto = flag.String("nextproto", "h2,h2-14", "Comma-separated list of NPN/ALPN protocol names to negotiate.")
 	flagNextProto = flag.String("nextproto", "h2,h2-14", "Comma-separated list of NPN/ALPN protocol names to negotiate.")
 	flagInsecure  = flag.Bool("insecure", false, "Whether to skip TLS cert validation")
 	flagInsecure  = flag.Bool("insecure", false, "Whether to skip TLS cert validation")
 	flagSettings  = flag.String("settings", "empty", "comma-separated list of KEY=value settings for the initial SETTINGS frame. The magic value 'empty' sends an empty initial settings frame, and the magic value 'omit' causes no initial settings frame to be sent.")
 	flagSettings  = flag.String("settings", "empty", "comma-separated list of KEY=value settings for the initial SETTINGS frame. The magic value 'empty' sends an empty initial settings frame, and the magic value 'omit' causes no initial settings frame to be sent.")
+	flagDial      = flag.String("dial", "", "optional ip:port to dial, to connect to a host:port but use a different SNI name (including a SNI name without DNS)")
 )
 )
 
 
 type command struct {
 type command struct {
@@ -147,11 +148,14 @@ func (app *h2i) Main() error {
 		InsecureSkipVerify: *flagInsecure,
 		InsecureSkipVerify: *flagInsecure,
 	}
 	}
 
 
-	hostAndPort := withPort(app.host)
+	hostAndPort := *flagDial
+	if hostAndPort == "" {
+		hostAndPort = withPort(app.host)
+	}
 	log.Printf("Connecting to %s ...", hostAndPort)
 	log.Printf("Connecting to %s ...", hostAndPort)
 	tc, err := tls.Dial("tcp", hostAndPort, cfg)
 	tc, err := tls.Dial("tcp", hostAndPort, cfg)
 	if err != nil {
 	if err != nil {
-		return fmt.Errorf("Error dialing %s: %v", withPort(app.host), err)
+		return fmt.Errorf("Error dialing %s: %v", hostAndPort, err)
 	}
 	}
 	log.Printf("Connected to %v", tc.RemoteAddr())
 	log.Printf("Connected to %v", tc.RemoteAddr())
 	defer tc.Close()
 	defer tc.Close()