xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_HSTS.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_HSTS
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerProtocol:
8*6236dae4SAndroid Build Coastguard Worker  - HTTP
9*6236dae4SAndroid Build Coastguard WorkerSee-also:
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_ALTSVC (3)
11*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_HSTS_CTRL (3)
12*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_RESOLVE (3)
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.74.0
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HSTS - HSTS cache filename
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTS, char *filename);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerMake the *filename* point to a filename to load an existing HSTS cache
31*6236dae4SAndroid Build Coastguard Workerfrom, and to store the cache in when the easy handle is closed. Setting a file
32*6236dae4SAndroid Build Coastguard Workername with this option also enables HSTS for this handle (the equivalent of
33*6236dae4SAndroid Build Coastguard Workersetting *CURLHSTS_ENABLE* with CURLOPT_HSTS_CTRL(3)).
34*6236dae4SAndroid Build Coastguard Worker
35*6236dae4SAndroid Build Coastguard WorkerIf the given file does not exist or contains no HSTS entries at startup, the
36*6236dae4SAndroid Build Coastguard WorkerHSTS cache simply starts empty. Setting the filename to NULL allows HSTS
37*6236dae4SAndroid Build Coastguard Workerwithout reading from or writing to any file. NULL also makes libcurl clear the
38*6236dae4SAndroid Build Coastguard Workerlist of files to read HSTS data from, if any such were previously set.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard WorkerIf this option is set multiple times, libcurl loads cache entries from each
41*6236dae4SAndroid Build Coastguard Workergiven file but only stores the last used name for later writing.
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard Worker# FILE FORMAT
44*6236dae4SAndroid Build Coastguard Worker
45*6236dae4SAndroid Build Coastguard WorkerThe HSTS cache is saved to and loaded from a text file with one entry per
46*6236dae4SAndroid Build Coastguard Workerphysical line. Each line in the file has the following format:
47*6236dae4SAndroid Build Coastguard Worker
48*6236dae4SAndroid Build Coastguard Worker    [host] [stamp]
49*6236dae4SAndroid Build Coastguard Worker
50*6236dae4SAndroid Build Coastguard Worker[host] is the domain name for the entry and the name is dot-prefixed if it is
51*6236dae4SAndroid Build Coastguard Workeran entry valid for all subdomains to the name as well or only for the exact
52*6236dae4SAndroid Build Coastguard Workername.
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard Worker[stamp] is the time (in UTC) when the entry expires and it uses the format
55*6236dae4SAndroid Build Coastguard Worker"YYYYMMDD HH:MM:SS".
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard WorkerLines starting with "#" are treated as comments and are ignored. There is
58*6236dae4SAndroid Build Coastguard Workercurrently no length or size limit.
59*6236dae4SAndroid Build Coastguard Worker
60*6236dae4SAndroid Build Coastguard Worker# DEFAULT
61*6236dae4SAndroid Build Coastguard Worker
62*6236dae4SAndroid Build Coastguard WorkerNULL, no filename
63*6236dae4SAndroid Build Coastguard Worker
64*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
65*6236dae4SAndroid Build Coastguard Worker
66*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
67*6236dae4SAndroid Build Coastguard Worker
68*6236dae4SAndroid Build Coastguard Worker~~~c
69*6236dae4SAndroid Build Coastguard Workerint main(void)
70*6236dae4SAndroid Build Coastguard Worker{
71*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
72*6236dae4SAndroid Build Coastguard Worker  if(curl) {
73*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_HSTS, "/home/user/.hsts-cache");
74*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
75*6236dae4SAndroid Build Coastguard Worker  }
76*6236dae4SAndroid Build Coastguard Worker}
77*6236dae4SAndroid Build Coastguard Worker~~~
78*6236dae4SAndroid Build Coastguard Worker
79*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
80*6236dae4SAndroid Build Coastguard Worker
81*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
82*6236dae4SAndroid Build Coastguard Worker
83*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
84