summaryrefslogtreecommitdiffstats
path: root/include/iprt/http.h
blob: 754e9c246af4f9141f30112bed822db249301cd6 (plain)
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/* $Id: http.h $ */
/** @file
 * IPRT - Simple HTTP/HTTPS Client API.
 */

/*
 * Copyright (C) 2012-2019 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 *
 * The contents of this file may alternatively be used under the terms
 * of the Common Development and Distribution License Version 1.0
 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
 * VirtualBox OSE distribution, in which case the provisions of the
 * CDDL are applicable instead of those of the GPL.
 *
 * You may elect to license modified versions of this file under the
 * terms and conditions of either the GPL or the CDDL or both.
 */

#ifndef IPRT_INCLUDED_http_h
#define IPRT_INCLUDED_http_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <iprt/types.h>

RT_C_DECLS_BEGIN

/** @defgroup grp_rt_http   RTHttp - Simple HTTP/HTTPS Client API
 * @ingroup grp_rt
 * @{
 */

/** @todo the following three definitions may move the iprt/types.h later. */
/** HTTP/HTTPS client handle. */
typedef R3PTRTYPE(struct RTHTTPINTERNAL *)      RTHTTP;
/** Pointer to a HTTP/HTTPS client handle. */
typedef RTHTTP                                 *PRTHTTP;
/** Nil HTTP/HTTPS client handle. */
#define NIL_RTHTTP                              ((RTHTTP)0)


/**
 * Creates a HTTP client instance.
 *
 * @returns IPRT status code.
 * @param   phHttp      Where to store the HTTP handle.
 */
RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);

/**
 * Resets a HTTP client instance.
 *
 * @returns IPRT status code.
 * @param   hHttp       Handle to the HTTP interface.
 * @param   fFlags      Flags, RTHTTP_RESET_F_XXX.
 */
RTR3DECL(int) RTHttpReset(RTHTTP hHttp, uint32_t fFlags);

/** @name RTHTTP_RESET_F_XXX - Flags for RTHttpReset.
 * @{ */
/** Keep the headers. */
#define RTHTTP_RESET_F_KEEP_HEADERS     RT_BIT_32(0)
/** Mask containing the valid flags. */
#define RTHTTP_RESET_F_VALID_MASK       UINT32_C(0x00000001)
/** @} */


/**
 * Destroys a HTTP client instance.
 *
 * @returns IPRT status code.
 * @param   hHttp       Handle to the HTTP interface.
 */
RTR3DECL(int) RTHttpDestroy(RTHTTP hHttp);


/**
 * Retrieve the redir location for 301 responses.
 *
 * @param   hHttp               Handle to the HTTP interface.
 * @param   ppszRedirLocation   Where to store the string.  To be freed with
 *                              RTStrFree().
 */
RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);

/**
 * Perform a simple blocking HTTP GET request.
 *
 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
 * different type and sheds a parameter.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          URL.
 * @param   ppszNotUtf8     Where to return the pointer to the HTTP response.
 *                          The string is of course zero terminated.  Use
 *                          RTHttpFreeReponseText to free.
 *
 * @remarks BIG FAT WARNING!
 *
 *          This function does not guarantee the that returned string is valid UTF-8 or
 *          any other kind of text encoding!
 *
 *          The caller must determine and validate the string encoding _before_
 *          passing it along to functions that expect UTF-8!
 *
 *          Also, this function does not guarantee that the returned string
 *          doesn't have embedded zeros and provides the caller no way of
 *          finding out!  If you are worried about the response from the HTTPD
 *          containing embedded zero's, use RTHttpGetBinary instead.
 */
RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);

/**
 * Perform a simple blocking HTTP HEAD request.
 *
 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
 * different type and sheds a parameter.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          URL.
 * @param   ppszNotUtf8     Where to return the pointer to the HTTP response.
 *                          The string is of course zero terminated.  Use
 *                          RTHttpFreeReponseText to free.
 *
 * @remarks BIG FAT WARNING!
 *
 *          This function does not guarantee the that returned string is valid UTF-8 or
 *          any other kind of text encoding!
 *
 *          The caller must determine and validate the string encoding _before_
 *          passing it along to functions that expect UTF-8!
 *
 *          Also, this function does not guarantee that the returned string
 *          doesn't have embedded zeros and provides the caller no way of
 *          finding out!  If you are worried about the response from the HTTPD
 *          containing embedded zero's, use RTHttpGetHeaderBinary instead.
 */
RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);

/**
 * Frees memory returned by RTHttpGetText.
 *
 * @param   pszNotUtf8      What RTHttpGetText returned.
 */
RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8);

/**
 * Perform a simple blocking HTTP GET request.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          The URL.
 * @param   ppvResponse     Where to store the HTTP response data.  Use
 *                          RTHttpFreeResponse to free.
 * @param   pcb             Size of the returned buffer.
 */
RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);

/**
 * Perform a simple blocking HTTP HEAD request.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          The URL.
 * @param   ppvResponse     Where to store the HTTP response data.  Use
 *                          RTHttpFreeResponse to free.
 * @param   pcb             Size of the returned buffer.
 */
RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);

/**
 * Frees memory returned by RTHttpGetBinary.
 *
 * @param   pvResponse      What RTHttpGetBinary returned.
 */
RTR3DECL(void) RTHttpFreeResponse(void *pvResponse);

/**
 * Perform a simple blocking HTTP request, writing the output to a file.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          The URL.
 * @param   pszDstFile      The destination file name.
 */
RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);

/** HTTP methods. */
typedef enum RTHTTPMETHOD
{
    RTHTTPMETHOD_INVALID = 0,
    RTHTTPMETHOD_GET,
    RTHTTPMETHOD_PUT,
    RTHTTPMETHOD_POST,
    RTHTTPMETHOD_PATCH,
    RTHTTPMETHOD_DELETE,
    RTHTTPMETHOD_HEAD,
    RTHTTPMETHOD_OPTIONS,
    RTHTTPMETHOD_TRACE,
    RTHTTPMETHOD_END,
    RTHTTPMETHOD_32BIT_HACK = 0x7fffffff
} RTHTTPMETHOD;

/**
 * Returns the name of the HTTP method.
 * @returns Read only string.
 * @param   enmMethod       The HTTP method to name.
 */
RTR3DECL(const char *) RTHttpMethodName(RTHTTPMETHOD enmMethod);

/**
 * Performs generic blocking HTTP request, optionally returning the body and headers.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          The URL.
 * @param   enmMethod       The HTTP method for the request.
 * @param   pvReqBody       Pointer to the request body. NULL if none.
 * @param   cbReqBody       Size of the request body. Zero if none.
 * @param   puHttpStatus    Where to return the HTTP status code. Optional.
 * @param   ppvHeaders      Where to return the headers. Optional.
 * @param   pcbHeaders      Where to return the header size.
 * @param   ppvBody         Where to return the body.  Optional.
 * @param   pcbBody         Where to return the body size.
 */
RTR3DECL(int) RTHttpPerform(RTHTTP hHttp, const char *pszUrl, RTHTTPMETHOD enmMethod, void const *pvReqBody, size_t cbReqBody,
                            uint32_t *puHttpStatus, void **ppvHeaders, size_t *pcbHeaders, void **ppvBody, size_t *pcbBody);


/**
 * Abort a pending HTTP request. A blocking RTHttpGet() call will return with
 * VERR_HTTP_ABORTED. It may take some time (current cURL implementation needs
 * up to 1 second) before the request is aborted.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 */
RTR3DECL(int) RTHttpAbort(RTHTTP hHttp);

/**
 * Tells the HTTP interface to use the system proxy configuration.
 *
 * @returns iprt status code.
 * @param   hHttp           The HTTP client handle.
 */
RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);

/**
 * Sets up the proxy according to the specified URL.
 *
 * @returns IPRT status code.
 * @retval  VWRN_WRONG_TYPE if the type isn't known/supported and we defaulted to 'http'.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszUrl          The proxy URL (libproxy style):
 *
 *                          [{type}"://"][{userid}[@{password}]:]{server}[":"{port}]
 *
 *                          Valid proxy types are: http (default), https, socks4, socks4a,
 *                          socks5, socks5h and direct.  Support for the socks and https
 *                          ones depends on the HTTP library we use.
 *
 *                          The port number defaults to 80 for http, 443 for https and 1080
 *                          for the socks ones.
 *
 *                          If this starts with "direct://", then no proxy will be used.
 *                          An empty or NULL string is equivalent to calling
 *                          RTHttpUseSystemProxySettings().
 */
RTR3DECL(int) RTHttpSetProxyByUrl(RTHTTP hHttp, const char *pszUrl);

/**
 * Specify proxy settings.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszProxyUrl     URL of the proxy server.
 * @param   uPort           port number of the proxy, use 0 for not specifying a port.
 * @param   pszProxyUser    Username, pass NULL for no authentication.
 * @param   pszProxyPwd     Password, pass NULL for no authentication.
 *
 * @todo    This API does not allow specifying the type of proxy server... We're
 *          currently assuming it's a HTTP proxy.
 *
 * @deprecated Use RTHttpSetProxyByUrl.
 */
RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pszProxyUrl, uint32_t uPort,
                             const char *pszProxyUser, const char *pszProxyPwd);

/**
 * Set follow redirects (3xx)
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   cMaxRedirects   Max number of redirects to follow.  Zero if no
 *                          redirects should be followed but instead returned
 *                          to caller.
 */
RTR3DECL(int) RTHttpSetFollowRedirects(RTHTTP hHttp, uint32_t cMaxRedirects);

/**
 * Set custom raw headers.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   cHeaders        Number of custom headers.
 * @param   papszHeaders    Array of headers in form "foo: bar".
 */
RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);

/** @name RTHTTPADDHDR_F_XXX - Flags for RTHttpAddRawHeader and RTHttpAddHeader
 * @{ */
#define RTHTTPADDHDR_F_BACK     UINT32_C(0) /**< Append the header. */
#define RTHTTPADDHDR_F_FRONT    UINT32_C(1) /**< Prepend the header. */
/** @} */

/**
 * Adds a raw header.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pszHeader       Header string on the form "foo: bar".
 * @param   fFlags          RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK.
 */
RTR3DECL(int) RTHttpAddRawHeader(RTHTTP hHttp, const char *pszHeader, uint32_t fFlags);

/**
 * Adds a header field and value.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pszField        The header field name.
 * @param   pszValue        The header field value.
 * @param   cchValue        The value length or RTSTR_MAX.
 * @param   fFlags          Only RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK,
 *                          may be extended with encoding controlling flags if
 *                          needed later.
 */
RTR3DECL(int) RTHttpAddHeader(RTHTTP hHttp, const char *pszField, const char *pszValue, size_t cchValue, uint32_t fFlags);

/**
 * Gets a header previously added using RTHttpSetHeaders, RTHttpAppendRawHeader
 * or RTHttpAppendHeader.
 *
 * @returns Pointer to the header value on if found, otherwise NULL.
 * @param   hHttp           The HTTP client handle.
 * @param   pszField        The field name (no colon).
 * @param   cchField        The length of the field name or RTSTR_MAX.
 */
RTR3DECL(const char *) RTHttpGetHeader(RTHTTP hHttp, const char *pszField, size_t cchField);

/**
 * Gets the number of headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
 *
 * @returns Number of headers.
 * @param   hHttp           The HTTP client handle.
 * @note    This can be slow and is only really intended for test cases and debugging!
 */
RTR3DECL(size_t)    RTHttpGetHeaderCount(RTHTTP hHttp);

/**
 * Gets a header by ordinal.
 *
 * Can be used together with RTHttpGetHeaderCount by test case and debug code to
 * iterate headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
 *
 * @returns The header string ("field: value").
 * @param   hHttp           The HTTP client handle.
 * @param   iOrdinal        The number of the header to get.
 * @note    This can be slow and is only really intended for test cases and debugging!
 */
RTR3DECL(const char *) RTHttpGetByOrdinal(RTHTTP hHttp, size_t iOrdinal);

/**
 * Sign all headers present according to pending "Signing HTTP Messages" RFC.
 *
 * Currently hardcoded RSA-SHA-256 algorithm choice.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   enmMethod       The HTTP method that will be used for the request.
 * @param   pszUrl          The target URL for the request.
 * @param   hKey            The RSA key to use when signing.
 * @param   pszKeyId        The key ID string corresponding to @a hKey.
 * @param   fFlags          Reserved for future, MBZ.
 *
 * @note    Caller is responsible for making all desired fields are present before
 *          making the call.
 *
 * @remarks Latest RFC draft at the time of writing:
 *          https://tools.ietf.org/html/draft-cavage-http-signatures-10
 */
RTR3DECL(int) RTHttpSignHeaders(RTHTTP hHttp, RTHTTPMETHOD enmMethod, const char *pszUrl,
                                RTCRKEY hKey, const char *pszKeyId, uint32_t fFlags);

/**
 * Tells the HTTP client instance to gather system CA certificates into a
 * temporary file and use it for HTTPS connections.
 *
 * This will be called automatically if a 'https' URL is presented and
 * RTHttpSetCaFile hasn't been called yet.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pErrInfo        Where to store additional error/warning information.
 *                          Optional.
 */
RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);

/**
 * Set a custom certification authority file, containing root certificates.
 *
 * @returns iprt status code.
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pszCAFile       File name containing root certificates.
 *
 * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
 */
RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);

/**
 * Gathers certificates into a cryptographic (certificate) store
 *
 * This is a just a combination of RTHttpGatherCaCertsInStore and
 * RTCrStoreCertExportAsPem.
 *
 * @returns IPRT status code.
 * @param   hStore          The certificate store to gather the certificates
 *                          in.
 * @param   fFlags          RTHTTPGATHERCACERT_F_XXX.
 * @param   pErrInfo        Where to store additional error/warning information.
 *                          Optional.
 */
RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);

/**
 * Gathers certificates into a file that can be used with RTHttpSetCAFile.
 *
 * This is a just a combination of RTHttpGatherCaCertsInStore and
 * RTCrStoreCertExportAsPem.
 *
 * @returns IPRT status code.
 * @param   pszCaFile       The output file.
 * @param   fFlags          RTHTTPGATHERCACERT_F_XXX.
 * @param   pErrInfo        Where to store additional error/warning information.
 *                          Optional.
 */
RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);

/**
 * Callback function to be called during RTHttpGet*().
 *
 * Register it using RTHttpSetDownloadProgressCallback().
 *
 * @param   hHttp           The HTTP client handle.
 * @param   pvUser          The user parameter specified when registering the callback.
 * @param   cbDowloadTotal  The content-length value, if available.
 *                          Warning! Not entirely clear what it will be if
 *                                   unavailable, probably 0.
 * @param   cbDowloaded     How much was downloaded thus far.
 */
typedef DECLCALLBACK(void) FNRTHTTPDOWNLDPROGRCALLBACK(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded);
/** Pointer to a download progress callback. */
typedef FNRTHTTPDOWNLDPROGRCALLBACK *PFNRTHTTPDOWNLDPROGRCALLBACK;

/**
 * Set the callback function which is called during (GET)
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pfnCallback     Progress function to be called. Set it to
 *                          NULL to disable the callback.
 * @param   pvUser          Convenience pointer for the callback function.
 */
RTR3DECL(int) RTHttpSetDownloadProgressCallback(RTHTTP hHttp, PFNRTHTTPDOWNLDPROGRCALLBACK pfnCallback, void *pvUser);

/**
 * Callback function for receiving body data.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pvBuf           Pointer to buffer with body bytes.
 * @param   cbBuf           Number of bytes in the buffer.
 * @param   uHttpStatus     The HTTP status code.
 * @param   offContent      The byte offset corresponding to the start of @a pvBuf.
 * @param   cbContent       The content length field value, UINT64_MAX if not available.
 * @param   pvUser          The user parameter.
 *
 * @note    The @a offContent parameter does not imply random access or anthing
 *          like that, it is just a convenience provided by the caller.  The
 *          value is the sum of the previous @a cbBuf values.
 */
typedef DECLCALLBACK(int) FNRTHTTPDOWNLOADCALLBACK(RTHTTP hHttp, void const *pvBuf, size_t cbBuf, uint32_t uHttpStatus,
                                                   uint64_t offContent, uint64_t cbContent, void *pvUser);
/** Pointer to a download data receiver callback. */
typedef FNRTHTTPDOWNLOADCALLBACK *PFNRTHTTPDOWNLOADCALLBACK;

/**
 * Set the callback function for downloading data (HTTP GET).
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   fFlags          RTHTTPDOWNLOAD_F_XXX.
 * @param   pfnCallback     The callback function.  Pass NULL to reset the callback.
 * @param   pvUser          Convenience pointer for the callback function.
 *
 * @remarks There can only be one download callback, so it is not possible to
 *          call this method for different status codes.  Only the last one
 *          with be honored.
 *
 * @note    This only works reliably with RTHttpPerform at the moment.
 */
RTR3DECL(int) RTHttpSetDownloadCallback(RTHTTP hHttp, uint32_t fFlags, PFNRTHTTPDOWNLOADCALLBACK pfnCallback, void *pvUser);

/** @name RTHTTPDOWNLOAD_F_XXX */
/** The lower 10 bits gives the HTTP status required by the callback.
 * For all other status codes, any body data will be returned via the
 * RTHttpPerform ppvBody/pcbBody return parameters. */
#define RTHTTPDOWNLOAD_F_ONLY_STATUS_MASK       UINT32_C(0x000003ff)
/** Callback requires no special HTTP status. */
#define RTHTTPDOWNLOAD_F_ANY_STATUS             UINT32_C(0x000003ff)
/** @} */


/**
 * Callback function for producing body data for uploading.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pvBuf           Where to put the data to upload
 * @param   cbBuf           Max number of bytes to provide.
 * @param   offContent      The byte offset corresponding to the start of @a pvBuf.
 * @param   pcbActual       Actual number of bytes provided.
 * @param   pvUser          The user parameter.
 *
 * @note    The @a offContent parameter does not imply random access or anthing
 *          like that, it is just a convenience provided by the caller.  The
 *          value is the sum of the previously returned @a *pcbActual values.
 */
typedef DECLCALLBACK(int) FNRTHTTPUPLOADCALLBACK(RTHTTP hHttp, void *pvBuf, size_t cbBuf, uint64_t offContent,
                                                 size_t *pcbActual, void *pvUser);
/** Pointer to an upload data producer callback. */
typedef FNRTHTTPUPLOADCALLBACK *PFNRTHTTPUPLOADCALLBACK;

/**
 * Set the callback function for providing upload data (HTTP PUT / POST).
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   cbContent       The content length, UINT64_MAX if not know or specified separately.
 * @param   pfnCallback     The callback function.  Pass NULL to reset the callback.
 * @param   pvUser          Convenience pointer for the callback function.
 *
 * @note    This only works reliably with RTHttpPerform at the moment.
 */
RTR3DECL(int) RTHttpSetUploadCallback(RTHTTP hHttp, uint64_t cbContent, PFNRTHTTPUPLOADCALLBACK pfnCallback, void *pvUser);


/**
 * Callback for consuming header fields.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   uMatchWord      Match word constructed by RTHTTP_MAKE_HDR_MATCH_WORD
 * @param   pchField        The field name (not zero terminated).
 *                          Not necessarily valid UTF-8!
 * @param   cchField        The length of the field.
 * @param   pchValue        The field value (not zero terminated).
 *                          Not necessarily valid UTF-8!
 * @param   cchValue        The length of the value.
 * @param   pvUser          The user parameter.
 *
 * @remarks This is called with two fictitious header fields too:
 *              - ':http-status-line' -- the HTTP/{version} {status-code} stuff.
 *              - ':end-of-headers'   -- marks the end of header callbacks.
 */
typedef DECLCALLBACK(int) FNRTHTTPHEADERCALLBACK(RTHTTP hHttp, uint32_t uMatchWord, const char *pchField, size_t cchField,
                                                 const char *pchValue, size_t cchValue, void *pvUser);
/** Pointer to a header field consumer callback. */
typedef FNRTHTTPHEADERCALLBACK *PFNRTHTTPHEADERCALLBACK;

/**
 * Forms a fast header match word.
 *
 * @returns Fast header match word.
 * @param   a_cchField      The length of the header field name.
 * @param   a_chLower1      The first character in the name, lowercased.
 * @param   a_chLower2      The second character in the name, lowercased.
 * @param   a_chLower3      The third character in the name, lowercased.
 */
#define RTHTTP_MAKE_HDR_MATCH_WORD(a_cchField, a_chLower1, a_chLower2, a_chLower3)   \
    RT_MAKE_U32_FROM_U8(a_cchField, a_chLower1, a_chLower2, a_chLower3)

/**
 * Set the callback function for processing header fields in the response.
 *
 * @returns IPRT status code.
 * @param   hHttp           The HTTP client handle.
 * @param   pfnCallback     The callback function.  Pass NULL to reset the callback.
 * @param   pvUser          Convenience pointer for the callback function.
 *
 * @note    This only works reliably with RTHttpPerform at the moment.
 */
RTR3DECL(int) RTHttpSetHeaderCallback(RTHTTP hHttp, PFNRTHTTPHEADERCALLBACK pfnCallback, void *pvUser);


/** @name thin wrappers for setting one or a few related curl options
 * @remarks Temporary. Will not be included in the 6.0 release!
 * @{ */
typedef size_t FNRTHTTPREADCALLBACKRAW(void *pbDst, size_t cbItem, size_t cItems, void *pvUser);
typedef FNRTHTTPREADCALLBACKRAW *PFNRTHTTPREADCALLBACKRAW;
#define RT_HTTP_READCALLBACK_ABORT 0x10000000 /* CURL_READFUNC_ABORT */
RTR3DECL(int) RTHttpRawSetReadCallback(RTHTTP hHttp, PFNRTHTTPREADCALLBACKRAW pfnRead, void *pvUser);

typedef size_t FNRTHTTPWRITECALLBACKRAW(char *pbSrc, size_t cbItem, size_t cItems, void *pvUser);
typedef FNRTHTTPWRITECALLBACKRAW *PFNRTHTTPWRITECALLBACKRAW;
RTR3DECL(int) RTHttpRawSetWriteCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACKRAW pfnWrite, void *pvUser);
RTR3DECL(int) RTHttpRawSetWriteHeaderCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACKRAW pfnWrite, void *pvUser);

RTR3DECL(int) RTHttpRawSetUrl(RTHTTP hHttp, const char *pszUrl);

RTR3DECL(int) RTHttpRawSetGet(RTHTTP hHttp);
RTR3DECL(int) RTHttpRawSetHead(RTHTTP hHttp);
RTR3DECL(int) RTHttpRawSetPost(RTHTTP hHttp);
RTR3DECL(int) RTHttpRawSetPut(RTHTTP hHttp);
RTR3DECL(int) RTHttpRawSetDelete(RTHTTP hHttp);
RTR3DECL(int) RTHttpRawSetCustomRequest(RTHTTP hHttp, const char *pszVerb);

RTR3DECL(int) RTHttpRawSetPostFields(RTHTTP hHttp, const void *pv, size_t cb);
RTR3DECL(int) RTHttpRawSetInfileSize(RTHTTP hHttp, RTFOFF cb);

RTR3DECL(int) RTHttpRawSetVerbose(RTHTTP hHttp, bool fValue);
RTR3DECL(int) RTHttpRawSetTimeout(RTHTTP hHttp, long sec);

RTR3DECL(int) RTHttpRawPerform(RTHTTP hHttp);

RTR3DECL(int) RTHttpRawGetResponseCode(RTHTTP hHttp, long *plCode);
/** @} */

/** @} */

RT_C_DECLS_END

#endif /* !IPRT_INCLUDED_http_h */