浏览代码

http2/h2i: add settings flag

Add a settings flag for users to send an initial settings frame
immediatly after connection to the server. By default an empty settings
frame is sent unless otherwise specified by the user.

Change-Id: Ic3b5ce638b6c8371557b6489fa7539050fcb630f
Reviewed-on: https://go-review.googlesource.com/16530
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Blake Mizerany 10 年之前
父节点
当前提交
c764672d0e
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13 0
      http2/h2i/h2i.go

+ 13 - 0
http2/h2i/h2i.go

@@ -42,6 +42,7 @@ import (
 var (
 	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")
+	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.")
 )
 
 type command struct {
@@ -239,6 +240,18 @@ func (app *h2i) logf(format string, args ...interface{}) {
 }
 
 func (app *h2i) readConsole() error {
+	if s := *flagSettings; s != "omit" {
+		var args []string
+		if s != "empty" {
+			args = strings.Split(s, ",")
+		}
+		_, c, ok := lookupCommand("settings")
+		if !ok {
+			panic("settings command not found")
+		}
+		c.run(app, args)
+	}
+
 	for {
 		line, err := app.term.ReadLine()
 		if err == io.EOF {