-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtypes.go
More file actions
309 lines (258 loc) · 11.1 KB
/
types.go
File metadata and controls
309 lines (258 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package cronet
// This file contains shared type definitions for both CGO and purego implementations.
// All pointer types are represented as uintptr for cross-implementation compatibility.
// Engine is an engine to process URLRequest, which uses the best HTTP stack
// available on the current platform. An instance of this class can be started
// using StartWithParams.
type Engine struct {
ptr uintptr
}
// EngineParams contains parameters for initializing a Cronet Engine.
type EngineParams struct {
ptr uintptr
}
// Buffer provided by the application to read and write data.
type Buffer struct {
ptr uintptr
}
// BufferCallback is called when the Buffer is destroyed.
type BufferCallback struct {
ptr uintptr
}
// Executor is an interface provided by the app to run commands asynchronously.
type Executor struct {
ptr uintptr
}
// Runnable is a command to be executed by an Executor.
type Runnable struct {
ptr uintptr
}
// URLRequest controls an HTTP request (GET, PUT, POST etc).
// Initialized by InitWithParams().
// Note: All methods must be called on the Executor passed to InitWithParams().
type URLRequest struct {
ptr uintptr
}
// URLRequestParams contains parameters for initializing a URLRequest.
type URLRequestParams struct {
ptr uintptr
}
// URLRequestCallback is used to receive callbacks from URLRequest.
type URLRequestCallback struct {
ptr uintptr
}
// URLResponseInfo contains response information for a URLRequest.
type URLResponseInfo struct {
ptr uintptr
}
// Error is the base error passed to URLRequestCallbackHandler.OnFailed().
type Error struct {
ptr uintptr
}
// DateTime represents a date and time value from cronet.
type DateTime struct {
ptr uintptr
}
// Metrics contains timing metrics for a URLRequest.
type Metrics struct {
ptr uintptr
}
// RequestFinishedInfo contains information about a finished request.
type RequestFinishedInfo struct {
ptr uintptr
}
// URLRequestFinishedInfoListener is called when a request finishes.
type URLRequestFinishedInfoListener struct {
ptr uintptr
}
// URLRequestStatusListener receives status updates for a URLRequest.
type URLRequestStatusListener struct {
ptr uintptr
}
// UploadDataProvider provides upload data to a URLRequest.
type UploadDataProvider struct {
ptr uintptr
}
// UploadDataSink is used by UploadDataProvider to signal events.
type UploadDataSink struct {
ptr uintptr
}
// StreamEngine is an opaque object representing a Bidirectional stream creating engine.
// Created and configured outside of this API to facilitate sharing with other components.
type StreamEngine struct {
ptr uintptr
}
// BidirectionalStream is an opaque object representing a Bidirectional Stream.
type BidirectionalStream struct {
ptr uintptr
}
// HTTPHeader represents an HTTP header key-value pair.
type HTTPHeader struct {
ptr uintptr
}
// QuicHint contains hints for QUIC protocol usage.
type QuicHint struct {
ptr uintptr
}
// PublicKeyPins contains public key pins for certificate validation.
type PublicKeyPins struct {
ptr uintptr
}
// BidirectionalStreamCallback
// Set of callbacks used to receive callbacks from bidirectional stream.
type BidirectionalStreamCallback interface {
// OnStreamReady
// Invoked when the stream is ready for reading and writing.
// Consumer may call BidirectionalStream.Read() to start reading data.
// Consumer may call BidirectionalStream.Write() to start writing
// data.
OnStreamReady(stream BidirectionalStream)
// OnResponseHeadersReceived
// Invoked when initial response headers are received.
// Consumer must call BidirectionalStream.Read() to start reading.
// Consumer may call BidirectionalStream.Write() to start writing or
// close the stream. Contents of |headers| is valid for duration of the call.
///
OnResponseHeadersReceived(stream BidirectionalStream, headers map[string]string, negotiatedProtocol string)
// OnReadCompleted
// Invoked when data is read into the buffer passed to
// BidirectionalStream.Read(). Only part of the buffer may be
// populated. To continue reading, call BidirectionalStream.Read().
// It may be invoked after on_response_trailers_received()}, if there was
// pending read data before trailers were received.
//
// If |bytesRead| is 0, it means the remote side has signaled that it will
// send no more data; future calls to BidirectionalStream.Read()
// will result in the OnReadCompleted() callback or OnSucceeded() callback if
// BidirectionalStream.Write() was invoked with endOfStream set to
// true.
OnReadCompleted(stream BidirectionalStream, bytesRead int)
// OnWriteCompleted
// Invoked when all data passed to BidirectionalStream.Write() is
// sent. To continue writing, call BidirectionalStream.Write().
OnWriteCompleted(stream BidirectionalStream)
// OnResponseTrailersReceived
// Invoked when trailers are received before closing the stream. Only invoked
// when server sends trailers, which it may not. May be invoked while there is
// read data remaining in local buffer. Contents of |trailers| is valid for
// duration of the call.
OnResponseTrailersReceived(stream BidirectionalStream, trailers map[string]string)
// OnSucceeded
// Invoked when there is no data to be read or written and the stream is
// closed successfully remotely and locally. Once invoked, no further callback
// methods will be invoked.
OnSucceeded(stream BidirectionalStream)
// OnFailed
// Invoked if the stream failed for any reason after
// BidirectionalStream.Start(). HTTP/2 error codes are
// mapped to chrome net error codes. Once invoked, no further callback methods
// will be invoked.
OnFailed(stream BidirectionalStream, netError int)
// OnCanceled
// Invoked if the stream was canceled via
// BidirectionalStream.Cancel(). Once invoked, no further callback
// methods will be invoked.
OnCanceled(stream BidirectionalStream)
}
// BidirectionalStreamHeaderArray is used to pass headers to bidirectional streams.
type BidirectionalStreamHeaderArray struct {
ptr uintptr
}
// EngineParamsHTTPCacheMode specifies HTTP cache mode.
type EngineParamsHTTPCacheMode int32
const (
// HTTPCacheModeDisabled disables caching for the engine.
HTTPCacheModeDisabled EngineParamsHTTPCacheMode = 0
// HTTPCacheModeInMemory enables in-memory caching, including HTTP data.
HTTPCacheModeInMemory EngineParamsHTTPCacheMode = 1
// HTTPCacheModeDiskNoHTTP enables on-disk caching, excluding HTTP data.
HTTPCacheModeDiskNoHTTP EngineParamsHTTPCacheMode = 2
// HTTPCacheModeDisk enables on-disk caching, including HTTP data.
HTTPCacheModeDisk EngineParamsHTTPCacheMode = 3
)
// URLRequestParamsRequestPriority specifies request priority level.
type URLRequestParamsRequestPriority int
const (
// URLRequestParamsRequestPriorityIdle
// Lowest request priority.
URLRequestParamsRequestPriorityIdle URLRequestParamsRequestPriority = 0
// URLRequestParamsRequestPriorityLowest
// Very low request priority.
URLRequestParamsRequestPriorityLowest URLRequestParamsRequestPriority = 1
// URLRequestParamsRequestPriorityLow
// Low request priority.
URLRequestParamsRequestPriorityLow URLRequestParamsRequestPriority = 2
// URLRequestParamsRequestPriorityMedium
// Medium request priority. This is the default priority given to the request.
URLRequestParamsRequestPriorityMedium URLRequestParamsRequestPriority = 3
// URLRequestParamsRequestPriorityHighest
// Highest request priority.
URLRequestParamsRequestPriorityHighest URLRequestParamsRequestPriority = 4
)
// URLRequestParamsIdempotency specifies idempotency of a request.
type URLRequestParamsIdempotency int
const (
URLRequestParamsIdempotencyDefaultIdempotency URLRequestParamsIdempotency = 0
URLRequestParamsIdempotencyIdempotent URLRequestParamsIdempotency = 1
URLRequestParamsIdempotencyNotIdempotent URLRequestParamsIdempotency = 2
)
// URLRequestStatusListenerStatus specifies the status of a URL request.
type URLRequestStatusListenerStatus int
const (
URLRequestStatusListenerStatusInvalid URLRequestStatusListenerStatus = -1
URLRequestStatusListenerStatusIdle URLRequestStatusListenerStatus = 0
URLRequestStatusListenerStatusWaitingForStalledSocketPool URLRequestStatusListenerStatus = 1
URLRequestStatusListenerStatusWaitingForAvailableSocket URLRequestStatusListenerStatus = 2
URLRequestStatusListenerStatusWaitingForDelegate URLRequestStatusListenerStatus = 3
URLRequestStatusListenerStatusWaitingForCache URLRequestStatusListenerStatus = 4
URLRequestStatusListenerStatusDownloadingPacFile URLRequestStatusListenerStatus = 5
URLRequestStatusListenerStatusResolvingProxyForURL URLRequestStatusListenerStatus = 6
URLRequestStatusListenerStatusResolvingHostInPacFile URLRequestStatusListenerStatus = 7
URLRequestStatusListenerStatusEstablishingProxyTunnel URLRequestStatusListenerStatus = 8
URLRequestStatusListenerStatusResolvingHost URLRequestStatusListenerStatus = 9
URLRequestStatusListenerStatusConnecting URLRequestStatusListenerStatus = 10
URLRequestStatusListenerStatusSSLHandshake URLRequestStatusListenerStatus = 11
URLRequestStatusListenerStatusSendingRequest URLRequestStatusListenerStatus = 12
URLRequestStatusListenerStatusWaitingForResponse URLRequestStatusListenerStatus = 13
URLRequestStatusListenerStatusReadingResponse URLRequestStatusListenerStatus = 14
)
// URLRequestFinishedInfoFinishedReason
// The reason why the request finished.
type URLRequestFinishedInfoFinishedReason int
const (
// URLRequestFinishedInfoFinishedReasonSucceeded
// The request succeeded.
URLRequestFinishedInfoFinishedReasonSucceeded URLRequestFinishedInfoFinishedReason = 0
// URLRequestFinishedInfoFinishedReasonFailed
// The request failed or returned an error.
URLRequestFinishedInfoFinishedReasonFailed URLRequestFinishedInfoFinishedReason = 1
// URLRequestFinishedInfoFinishedReasonCanceled
// The request was canceled.
URLRequestFinishedInfoFinishedReasonCanceled URLRequestFinishedInfoFinishedReason = 2
)
// Dialer is a callback function for custom TCP connection establishment.
// address: IP address string (e.g. "1.2.3.4" or "::1")
// port: Port number
// Returns: connected socket fd on success, negative net error code on failure.
// Common error codes:
//
// ERR_CONNECTION_REFUSED (-102)
// ERR_CONNECTION_FAILED (-104)
// ERR_ADDRESS_UNREACHABLE (-109)
// ERR_CONNECTION_TIMED_OUT (-118)
type Dialer func(address string, port uint16) int
// UDPDialer is a callback function for custom UDP socket creation.
// address: IP address string (e.g. "1.2.3.4" or "::1")
// port: Port number
// Returns:
// - fd: socket fd on success, negative net error code on failure
// - localAddress: local IP address string (may be empty)
// - localPort: local port number
//
// The returned socket can be:
// - AF_INET/AF_INET6 SOCK_DGRAM: Standard UDP socket (may be connected)
// - AF_UNIX SOCK_DGRAM: Unix domain datagram socket (Unix/macOS/Linux)
// - AF_UNIX SOCK_STREAM: Unix domain stream socket (Windows, with framing)
//
// Cronet will NOT call connect() on the returned socket.
type UDPDialer func(address string, port uint16) (fd int, localAddress string, localPort uint16)