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