Skip to main content

browser_protocol/cachestorage/
mod.rs

1use serde::{Serialize, Deserialize};
2
3/// Unique identifier of the Cache object.
4
5pub type CacheId = String;
6
7/// type of HTTP response cached
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
10pub enum CachedResponseType {
11    #[default]
12    Basic,
13    Cors,
14    Default,
15    Error,
16    OpaqueResponse,
17    OpaqueRedirect,
18}
19
20/// Data entry.
21
22#[derive(Debug, Clone, Serialize, Deserialize, Default)]
23#[serde(rename_all = "camelCase")]
24pub struct DataEntry {
25    /// Request URL.
26
27    pub requestURL: String,
28    /// Request method.
29
30    pub requestMethod: String,
31    /// Request headers
32
33    pub requestHeaders: Vec<Header>,
34    /// Number of seconds since epoch.
35
36    pub responseTime: f64,
37    /// HTTP response status code.
38
39    pub responseStatus: i64,
40    /// HTTP response status text.
41
42    pub responseStatusText: String,
43    /// HTTP response type
44
45    pub responseType: CachedResponseType,
46    /// Response headers
47
48    pub responseHeaders: Vec<Header>,
49}
50
51/// Cache identifier.
52
53#[derive(Debug, Clone, Serialize, Deserialize, Default)]
54#[serde(rename_all = "camelCase")]
55pub struct Cache {
56    /// An opaque unique id of the cache.
57
58    pub cacheId: CacheId,
59    /// Security origin of the cache.
60
61    pub securityOrigin: String,
62    /// Storage key of the cache.
63
64    pub storageKey: String,
65    /// Storage bucket of the cache.
66
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub storageBucket: Option<crate::storage::StorageBucket>,
69    /// The name of the cache.
70
71    pub cacheName: String,
72}
73
74
75#[derive(Debug, Clone, Serialize, Deserialize, Default)]
76#[serde(rename_all = "camelCase")]
77pub struct Header {
78
79    pub name: String,
80
81    pub value: String,
82}
83
84/// Cached response
85
86#[derive(Debug, Clone, Serialize, Deserialize, Default)]
87#[serde(rename_all = "camelCase")]
88pub struct CachedResponse {
89    /// Entry content, base64-encoded. (Encoded as a base64 string when passed over JSON)
90
91    pub body: String,
92}
93
94/// Deletes a cache.
95
96#[derive(Debug, Clone, Serialize, Deserialize, Default)]
97#[serde(rename_all = "camelCase")]
98pub struct DeleteCacheParams {
99    /// Id of cache for deletion.
100
101    pub cacheId: CacheId,
102}
103
104/// Deletes a cache entry.
105
106#[derive(Debug, Clone, Serialize, Deserialize, Default)]
107#[serde(rename_all = "camelCase")]
108pub struct DeleteEntryParams {
109    /// Id of cache where the entry will be deleted.
110
111    pub cacheId: CacheId,
112    /// URL spec of the request.
113
114    pub request: String,
115}
116
117/// Requests cache names.
118
119#[derive(Debug, Clone, Serialize, Deserialize, Default)]
120#[serde(rename_all = "camelCase")]
121pub struct RequestCacheNamesParams {
122    /// At least and at most one of securityOrigin, storageKey, storageBucket must be specified.
123    /// Security origin.
124
125    #[serde(skip_serializing_if = "Option::is_none")]
126    pub securityOrigin: Option<String>,
127    /// Storage key.
128
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub storageKey: Option<String>,
131    /// Storage bucket. If not specified, it uses the default bucket.
132
133    #[serde(skip_serializing_if = "Option::is_none")]
134    pub storageBucket: Option<crate::storage::StorageBucket>,
135}
136
137/// Requests cache names.
138
139#[derive(Debug, Clone, Serialize, Deserialize, Default)]
140#[serde(rename_all = "camelCase")]
141pub struct RequestCacheNamesReturns {
142    /// Caches for the security origin.
143
144    pub caches: Vec<Cache>,
145}
146
147/// Fetches cache entry.
148
149#[derive(Debug, Clone, Serialize, Deserialize, Default)]
150#[serde(rename_all = "camelCase")]
151pub struct RequestCachedResponseParams {
152    /// Id of cache that contains the entry.
153
154    pub cacheId: CacheId,
155    /// URL spec of the request.
156
157    pub requestURL: String,
158    /// headers of the request.
159
160    pub requestHeaders: Vec<Header>,
161}
162
163/// Fetches cache entry.
164
165#[derive(Debug, Clone, Serialize, Deserialize, Default)]
166#[serde(rename_all = "camelCase")]
167pub struct RequestCachedResponseReturns {
168    /// Response read from the cache.
169
170    pub response: CachedResponse,
171}
172
173/// Requests data from cache.
174
175#[derive(Debug, Clone, Serialize, Deserialize, Default)]
176#[serde(rename_all = "camelCase")]
177pub struct RequestEntriesParams {
178    /// ID of cache to get entries from.
179
180    pub cacheId: CacheId,
181    /// Number of records to skip.
182
183    #[serde(skip_serializing_if = "Option::is_none")]
184    pub skipCount: Option<u64>,
185    /// Number of records to fetch.
186
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub pageSize: Option<u64>,
189    /// If present, only return the entries containing this substring in the path
190
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub pathFilter: Option<String>,
193}
194
195/// Requests data from cache.
196
197#[derive(Debug, Clone, Serialize, Deserialize, Default)]
198#[serde(rename_all = "camelCase")]
199pub struct RequestEntriesReturns {
200    /// Array of object store data entries.
201
202    pub cacheDataEntries: Vec<DataEntry>,
203    /// Count of returned entries from this storage. If pathFilter is empty, it
204    /// is the count of all entries from this storage.
205
206    pub returnCount: f64,
207}