Skip to main content

browser_protocol/cachestorage/
mod.rs

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