1package http2interop 2 3import ( 4 "bytes" 5 "io" 6 "strings" 7) 8 9// HTTP1Frame is not a real frame, but rather a way to represent an http1.x response. 10type HTTP1Frame struct { 11 Header FrameHeader 12 Data []byte 13} 14 15func (f *HTTP1Frame) GetHeader() *FrameHeader { 16 return &f.Header 17} 18 19func (f *HTTP1Frame) ParsePayload(r io.Reader) error { 20 var buf bytes.Buffer 21 if _, err := io.Copy(&buf, r); err != nil { 22 return err 23 } 24 f.Data = buf.Bytes() 25 return nil 26} 27 28func (f *HTTP1Frame) MarshalPayload() ([]byte, error) { 29 return []byte(string(f.Data)), nil 30} 31 32func (f *HTTP1Frame) MarshalBinary() ([]byte, error) { 33 buf, err := f.Header.MarshalBinary() 34 if err != nil { 35 return nil, err 36 } 37 38 buf = append(buf, f.Data...) 39 40 return buf, nil 41} 42 43func (f *HTTP1Frame) String() string { 44 s := string(f.Data) 45 parts := strings.SplitN(s, "\n", 2) 46 headerleft, _ := f.Header.MarshalBinary() 47 48 return strings.TrimSpace(string(headerleft) + parts[0]) 49} 50