1
2
3
4
5 package http2
6
7 import (
8 "context"
9 "crypto/tls"
10 "errors"
11 "io"
12 "log"
13 "mime/multipart"
14 "net"
15 "net/http/internal"
16 "net/textproto"
17 "net/url"
18 "time"
19 )
20
21
22
23
24
25
26
27
28
29 var (
30 NoBody io.ReadCloser
31 LocalAddrContextKey any
32 )
33
34 var (
35 ErrAbortHandler = internal.ErrAbortHandler
36 ErrBodyNotAllowed = internal.ErrBodyNotAllowed
37 ErrNotSupported = errors.ErrUnsupported
38 ErrSkipAltProtocol = internal.ErrSkipAltProtocol
39 )
40
41
42 type ClientRequest struct {
43 Context context.Context
44 Method string
45 URL *url.URL
46 Header Header
47 Trailer Header
48 Body io.ReadCloser
49 Host string
50 GetBody func() (io.ReadCloser, error)
51 ContentLength int64
52 Cancel <-chan struct{}
53 Close bool
54 ResTrailer *Header
55
56
57 stream clientStream
58 }
59
60
61
62
63
64 func (req *ClientRequest) Clone() *ClientRequest {
65 return &ClientRequest{
66 Context: req.Context,
67 Method: req.Method,
68 URL: req.URL,
69 Header: req.Header,
70 Trailer: req.Trailer,
71 Body: req.Body,
72 Host: req.Host,
73 GetBody: req.GetBody,
74 ContentLength: req.ContentLength,
75 Cancel: req.Cancel,
76 Close: req.Close,
77 ResTrailer: req.ResTrailer,
78 }
79 }
80
81
82 type ClientResponse struct {
83 Status string
84 StatusCode int
85 ContentLength int64
86 Uncompressed bool
87 Header Header
88 Trailer Header
89 Body io.ReadCloser
90 TLS *tls.ConnectionState
91 }
92
93 type Header = textproto.MIMEHeader
94
95
96 type TransportConfig interface {
97 MaxHeaderListSize() int64
98 MaxResponseHeaderBytes() int64
99 DisableCompression() bool
100 DisableKeepAlives() bool
101 ExpectContinueTimeout() time.Duration
102 ResponseHeaderTimeout() time.Duration
103 IdleConnTimeout() time.Duration
104 HTTP2Config() Config
105 }
106
107
108 type ServerConfig interface {
109 MaxHeaderBytes() int
110 MaxHeaderValueCount() int
111 ConnState(net.Conn, ConnState)
112 DoKeepAlives() bool
113 WriteTimeout() time.Duration
114 SendPingTimeout() time.Duration
115 ErrorLog() *log.Logger
116 ReadTimeout() time.Duration
117 HTTP2Config() Config
118 DisableClientPriority() bool
119 IdleTimeout() time.Duration
120 }
121
122 type Handler interface {
123 ServeHTTP(*ResponseWriter, *ServerRequest)
124 }
125
126 type ResponseWriter = responseWriter
127
128 type PushOptions struct {
129 Method string
130 Header Header
131 }
132
133
134 type ServerRequest struct {
135 Context context.Context
136 Proto string
137 ProtoMajor int
138 ProtoMinor int
139 Method string
140 URL *url.URL
141 Header Header
142 Trailer Header
143 Body io.ReadCloser
144 Host string
145 ContentLength int64
146 RemoteAddr string
147 RequestURI string
148 TLS *tls.ConnectionState
149 MultipartForm *multipart.Form
150 }
151
152
153 type ConnState int
154
155 const (
156 ConnStateNew ConnState = iota
157 ConnStateActive
158 ConnStateIdle
159 ConnStateHijacked
160 ConnStateClosed
161 )
162
View as plain text