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 ConnState(net.Conn, ConnState)
111 DoKeepAlives() bool
112 WriteTimeout() time.Duration
113 SendPingTimeout() time.Duration
114 ErrorLog() *log.Logger
115 ReadTimeout() time.Duration
116 HTTP2Config() Config
117 DisableClientPriority() bool
118 IdleTimeout() time.Duration
119 }
120
121 type Handler interface {
122 ServeHTTP(*ResponseWriter, *ServerRequest)
123 }
124
125 type ResponseWriter = responseWriter
126
127 type PushOptions struct {
128 Method string
129 Header Header
130 }
131
132
133 type ServerRequest struct {
134 Context context.Context
135 Proto string
136 ProtoMajor int
137 ProtoMinor int
138 Method string
139 URL *url.URL
140 Header Header
141 Trailer Header
142 Body io.ReadCloser
143 Host string
144 ContentLength int64
145 RemoteAddr string
146 RequestURI string
147 TLS *tls.ConnectionState
148 MultipartForm *multipart.Form
149 }
150
151
152 type ConnState int
153
154 const (
155 ConnStateNew ConnState = iota
156 ConnStateActive
157 ConnStateIdle
158 ConnStateHijacked
159 ConnStateClosed
160 )
161
View as plain text