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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
* Hurl (https://hurl.dev)
* Copyright (C) 2026 Orange
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use ;
use ptr;
use Duration;
use Error;
use Easy;
use ;
/// Some definitions not present in curl-sys
const CURLINFO_OFF_T: CURLINFO = 0x600000;
const CURLINFO_TOTAL_TIME_T: CURLINFO = CURLINFO_OFF_T + 50;
const CURLINFO_NAMELOOKUP_TIME_T: CURLINFO = CURLINFO_OFF_T + 51;
const CURLINFO_CONNECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 52;
const CURLINFO_PRETRANSFER_TIME_T: CURLINFO = CURLINFO_OFF_T + 53;
const CURLINFO_STARTTRANSFER_TIME_T: CURLINFO = CURLINFO_OFF_T + 54;
const CURLINFO_APPCONNECT_TIME_T: CURLINFO = CURLINFO_OFF_T + 56;
const CURLINFO_CONN_ID: CURLINFO = CURLINFO_OFF_T + 64;
/// Represents certificate information.
/// `data` has format "name:content";
;
/// Returns the information of the first certificate in the certificates chain.
/// Extracts PEM certificate value from certificate info data.
/// Returns the connection identifier use by this libcurl handle.
// Timing of a typical HTTP exchange (over TLS 1.2 connection) from libcurl
// (courtesy of <https://blog.cloudflare.com/a-question-of-timing/>
// =========================================================================
//
// ┌───────────┐ ┌──────────────┐ ┌──────────────┐
// │ Client │ │ DNS Server │ │ Web Server │
// └─────┬─────┘ └──────┬───────┘ └──────┬───────┘
// │ │ │
// ┌ 0s ├────── DNS Request ─────►│ │
// DNS │ │ │ DNS Resolver │
// Lookup < │ │ e.g. 1.1.1.1 │
// │ │◄───── DNS Response ─────┘ │
// └ time_namelookup 1.510s │ │
// ┌ ├────────────────── SYN ────────────────────►│
// TCP < │ │
// Handshake └ time_connect 1.757s │◄────────────── SYN/ACK ───────────────────┤
// ┌ │ │
// │ │ │
// │ ├────────────────── ACK ────────────────────►│
// │ ├────────────── ClientHello ────────────────►│
// │ │ │
// │ │◄───────────── ServerHello ─────────────────┤
// SSL < │ Certificate │
// Handshake │ │ │
// │ ├───────────── ClientKeyExch, ──────────────►│
// │ │ ChangeCipherSpec │
// │ │ │
// │ │◄────────── ChangeCipherSpec ───────────────┤
// └ time_appconnect 2.256s │ Finished │
// ┌ time_pretransfer 2.259s ├─────────────── HTTP GET ──────────────────►│
// │ │ │
// Wait < │ │
// │ │ │
// └ time_starttransfer 2.506s │ │
// ┌ │◄───────────────────────────────────────────┤
// Data │ │◄─────────────── Response ──────────────────┤
// Transfer < │ ... │
// │ │◄───────────────────────────────────────────┤
// └ time_total 3.001s │ │
// ▼ ▼
/// Get the name lookup time.
///
/// Returns the total time in microseconds from the start until the name resolving was completed.
///
/// Corresponds to [`CURLINFO_NAMELOOKUP_TIME_T`] and may return an error if the
/// option isn't supported.
/// Get the time until connect.
///
/// Returns the total time in microseconds from the start until the connection to the remote host (or proxy) was completed.
///
/// Corresponds to [`CURLINFO_CONNECT_TIME_T`] and may return an error if the
/// option isn't supported.
/// Get the time until the SSL/SSH handshake is completed.
///
/// Returns the total time in microseconds it took from the start until the SSL/SSH
/// connect/handshake to the remote host was completed. This time is most often
/// very near to the [`pretransfer_time_t`] time, except for cases such as
/// HTTP pipelining where the pretransfer time can be delayed due to waits in
/// line for the pipeline and more.
///
/// Corresponds to [`CURLINFO_APPCONNECT_TIME_T`] and may return an error if the
/// option isn't supported.
/// Get the time until the file transfer start.
///
/// Returns the total time in microseconds it took from the start until the file
/// transfer is just about to begin. This includes all pre-transfer commands
/// and negotiations that are specific to the particular protocol(s) involved.
/// It does not involve the sending of the protocol- specific request that
/// triggers a transfer.
///
/// Corresponds to [`CURLINFO_PRETRANSFER_TIME`] and may return an error if the
/// option isn't supported.
/// Get the time in microseconds until the first byte is received.
///
/// Returns the total time it took from the start until the first
/// byte is received by libcurl. This includes [`pretransfer_time_t`] and
/// also the time the server needs to calculate the result.
///
/// Corresponds to [`CURLINFO_STARTTRANSFER_TIME`] and may return an error if the
/// option isn't supported.
/// Get total time of previous transfer
///
/// Returns the total time in microseconds for the previous transfer,
/// including name resolving, TCP connect etc.
///
/// Corresponds to [`CURLINFO_TOTAL_TIME_T`] and may return an error if the
/// option isn't supported.
/// Read .netrc information from a file.
/// Converts an instance of libcurl linked list [`curl_slist`] to a vec of [`String`].
/// Check if the return code `rc` is OK, and returns an error if not.
// // Iterator based implementation more similar to curl crates List implementation.
// // See <https://github.com/alexcrichton/curl-rust/blob/main/src/easy/list.rs>
// pub struct CertInfo2 {
// raw: *mut curl_certinfo,
// }
//
// // An iterator over CertInfo2
// pub struct Iter<'a> {
// me: &'a CertInfo2,
// cur: u32,
// }
//
// pub unsafe fn from_raw(raw: *mut curl_certinfo) -> CertInfo2 {
// CertInfo2 { raw }
// }
//
// impl CertInfo2 {
// pub fn new() -> CertInfo2 {
// CertInfo2 {
// raw: ptr::null_mut(),
// }
// }
//
// pub fn iter(&self) -> Iter {
// Iter {
// me: self,
// cur: 0,
// }
// }
// }
//
// impl<'a> IntoIterator for &'a CertInfo2 {
// type Item = *mut curl_slist;
// type IntoIter = Iter<'a>;
//
// fn into_iter(self) -> Iter<'a> {
// self.iter()
// }
// }
//
// impl<'a> Iterator for Iter<'a> {
// type Item = *mut curl_slist;
//
// fn next(&mut self) -> Option<*mut curl_slist> {
// unsafe {
// if self.cur >= (*self.me.raw).num_of_certs as u32 {
// return None
// }
// let slist = *((*self.me.raw).certinfo.offset(self.cur as isize));
// self.cur += 1;
// Some(slist)
// }
// }
// }