package pkg import ( "errors" "strconv" "strings" ) type HTTP2Profile struct { ProfileCommon ActivationModes []string `json:"activation_modes"` //activation-modes { alpn npn } ConcurrentStreamPerConn int `json:"concurrent_streams_per_connection"` //concurrent-streams-per-connection 10 ConnIdleTimeout int `json:"connection_idle_timeout"` //connection-idle-timeout 300 EnforceTLSReq string `json:"enforce_tls_requirements"` //enforce-tls-requirements enabled FrameSize int `json:"frame_size"` //frame-size 2048 HeaderTableSize int `json:"header_table_size"` //header-table-size 4096 InsertHeader string `json:"insert_header"` //insert-header disabled InsertHeaderName string `json:"insert_header_name"` //insert-header-name X-HTTP2 ReceiveWindow int `json:"receive_window"` //receive-window 32 WriteSize int `json:"write_size"` //write-size 16384 } func ParseHTTP2(raw string) (*HTTP2Profile, error) { p := new(HTTP2Profile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile http2") { return nil, errors.New("not an http2 profile") } p.ProfileCommon = parseCommon(raw) p.ActivationModes = []string{} for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "activation-modes": if f[1] != "none" { p.ActivationModes = append(p.ActivationModes, f[2:len(f)-1]...) } case "concurrent-streams-per-connection": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ConcurrentStreamPerConn = i case "connection-idle-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ConnIdleTimeout = i case "enforce-tls-requirements": p.EnforceTLSReq = f[1] case "frame-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.FrameSize = i case "header-table-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.HeaderTableSize = i case "insert-header": p.InsertHeader = strings.Join(f[1:], " ") case "insert-header-name": p.InsertHeaderName = strings.Join(f[1:], " ") case "receive-window": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.ReceiveWindow = i case "write-size": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.WriteSize = i } } return p, nil }