github.com/alejandroesc/spdy@v0.0.0-20200317064415-01a02f0eb389/shared_interfaces.go (about) 1 package spdy 2 3 import ( 4 "io" 5 "net" 6 "net/http" 7 8 "github.com/SlyMarbo/spdy/common" 9 "github.com/SlyMarbo/spdy/spdy2" 10 "github.com/SlyMarbo/spdy/spdy3" 11 ) 12 13 // Connection represents a SPDY connection. The connection should 14 // be started with a call to Run, which will return once the 15 // connection has been terminated. The connection can be ended 16 // early by using Close. 17 type Conn interface { 18 http.CloseNotifier 19 Close() error 20 Conn() net.Conn 21 Request(request *http.Request, receiver common.Receiver, priority common.Priority) (common.Stream, error) 22 RequestResponse(request *http.Request, receiver common.Receiver, priority common.Priority) (*http.Response, error) 23 Run() error 24 } 25 26 var _ = Conn(&spdy2.Conn{}) 27 var _ = Conn(&spdy3.Conn{}) 28 29 // Stream contains a single SPDY stream. 30 type Stream interface { 31 http.CloseNotifier 32 http.ResponseWriter 33 Close() error 34 Conn() common.Conn 35 ReceiveFrame(common.Frame) error 36 Run() error 37 State() *common.StreamState 38 StreamID() common.StreamID 39 } 40 41 var _ = Stream(&spdy2.PushStream{}) 42 var _ = Stream(&spdy2.RequestStream{}) 43 var _ = Stream(&spdy2.ResponseStream{}) 44 var _ = Stream(&spdy3.PushStream{}) 45 var _ = Stream(&spdy3.RequestStream{}) 46 var _ = Stream(&spdy3.ResponseStream{}) 47 48 // PriorityStream represents a SPDY stream with a priority. 49 type PriorityStream interface { 50 Stream 51 52 // Priority returns the stream's 53 // priority. 54 Priority() common.Priority 55 } 56 57 var _ = PriorityStream(&spdy2.ResponseStream{}) 58 var _ = PriorityStream(&spdy3.ResponseStream{}) 59 60 // Compressor is used to compress the text header of a SPDY frame. 61 type Compressor interface { 62 io.Closer 63 Compress(http.Header) ([]byte, error) 64 } 65 66 // Decompressor is used to decompress the text header of a SPDY frame. 67 type Decompressor interface { 68 Decompress([]byte) (http.Header, error) 69 } 70 71 // Pinger represents something able to send and 72 // receive PING frames. 73 type Pinger interface { 74 Ping() (<-chan bool, error) 75 } 76 77 var _ = Pinger(&spdy2.Conn{}) 78 var _ = Pinger(&spdy3.Conn{}) 79 80 // Pusher represents something able to send 81 // server puhes. 82 type Pusher interface { 83 Push(url string, origin common.Stream) (common.PushStream, error) 84 } 85 86 var _ = Pusher(&spdy2.Conn{}) 87 var _ = Pusher(&spdy3.Conn{}) 88 89 // SetFlowController represents a connection 90 // which can have its flow control mechanism 91 // customised. 92 type SetFlowController interface { 93 SetFlowControl(common.FlowControl) 94 } 95 96 var _ = SetFlowController(&spdy3.Conn{})