fastly_api/apis/
request_settings_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`create_request_settings`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateRequestSettingsParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32
21}
22
23/// struct for passing parameters to the method [`delete_request_settings`]
24#[derive(Clone, Debug, Default)]
25pub struct DeleteRequestSettingsParams {
26    /// Alphanumeric string identifying the service.
27    pub service_id: String,
28    /// Integer identifying a service version.
29    pub version_id: i32,
30    /// Name for the request settings.
31    pub request_settings_name: String
32}
33
34/// struct for passing parameters to the method [`get_request_settings`]
35#[derive(Clone, Debug, Default)]
36pub struct GetRequestSettingsParams {
37    /// Alphanumeric string identifying the service.
38    pub service_id: String,
39    /// Integer identifying a service version.
40    pub version_id: i32,
41    /// Name for the request settings.
42    pub request_settings_name: String
43}
44
45/// struct for passing parameters to the method [`list_request_settings`]
46#[derive(Clone, Debug, Default)]
47pub struct ListRequestSettingsParams {
48    /// Alphanumeric string identifying the service.
49    pub service_id: String,
50    /// Integer identifying a service version.
51    pub version_id: i32
52}
53
54/// struct for passing parameters to the method [`update_request_settings`]
55#[derive(Clone, Debug, Default)]
56pub struct UpdateRequestSettingsParams {
57    /// Alphanumeric string identifying the service.
58    pub service_id: String,
59    /// Integer identifying a service version.
60    pub version_id: i32,
61    /// Name for the request settings.
62    pub request_settings_name: String,
63    /// Allows you to terminate request handling and immediately perform an action.
64    pub action: Option<String>,
65    /// Sets the host header.
66    pub default_host: Option<String>,
67    /// Comma separated list of varnish request object fields that should be in the hash key.
68    pub hash_keys: Option<String>,
69    /// Name for the request settings.
70    pub name: Option<String>,
71    /// Condition which, if met, will select this configuration during a request. Optional.
72    pub request_condition: Option<String>,
73    /// Short for X-Forwarded-For.
74    pub xff: Option<String>,
75    /// Disable collapsed forwarding, so you don't wait for other objects to origin.
76    pub bypass_busy_wait: Option<i32>,
77    /// Allows you to force a cache miss for the request. Replaces the item in the cache if the content is cacheable.
78    pub force_miss: Option<i32>,
79    /// Forces the request use SSL (redirects a non-SSL to SSL).
80    pub force_ssl: Option<i32>,
81    /// Injects Fastly-Geo-Country, Fastly-Geo-City, and Fastly-Geo-Region into the request headers.
82    pub geo_headers: Option<i32>,
83    /// How old an object is allowed to be to serve stale-if-error or stale-while-revalidate.
84    pub max_stale_age: Option<i32>,
85    /// Injects the X-Timer info into the request for viewing origin fetch durations.
86    pub timer_support: Option<i32>
87}
88
89
90/// struct for typed errors of method [`create_request_settings`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum CreateRequestSettingsError {
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`delete_request_settings`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum DeleteRequestSettingsError {
101    UnknownValue(serde_json::Value),
102}
103
104/// struct for typed errors of method [`get_request_settings`]
105#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum GetRequestSettingsError {
108    UnknownValue(serde_json::Value),
109}
110
111/// struct for typed errors of method [`list_request_settings`]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum ListRequestSettingsError {
115    UnknownValue(serde_json::Value),
116}
117
118/// struct for typed errors of method [`update_request_settings`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum UpdateRequestSettingsError {
122    UnknownValue(serde_json::Value),
123}
124
125
126/// Creates a new Request Settings object.
127pub async fn create_request_settings(configuration: &mut configuration::Configuration, params: CreateRequestSettingsParams) -> Result<crate::models::RequestSettingsResponse, Error<CreateRequestSettingsError>> {
128    let local_var_configuration = configuration;
129
130    // unbox the parameters
131    let service_id = params.service_id;
132    let version_id = params.version_id;
133
134
135    let local_var_client = &local_var_configuration.client;
136
137    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/request_settings", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
138    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
139
140    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
141        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
142    }
143    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
144        let local_var_key = local_var_apikey.key.clone();
145        let local_var_value = match local_var_apikey.prefix {
146            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
147            None => local_var_key,
148        };
149        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
150    };
151
152    let local_var_req = local_var_req_builder.build()?;
153    let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155    if "POST" != "GET" && "POST" != "HEAD" {
156      let headers = local_var_resp.headers();
157      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
158          Some(v) => v.to_str().unwrap().parse().unwrap(),
159          None => configuration::DEFAULT_RATELIMIT,
160      };
161      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
162          Some(v) => v.to_str().unwrap().parse().unwrap(),
163          None => 0,
164      };
165    }
166
167    let local_var_status = local_var_resp.status();
168    let local_var_content = local_var_resp.text().await?;
169
170    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
171        serde_json::from_str(&local_var_content).map_err(Error::from)
172    } else {
173        let local_var_entity: Option<CreateRequestSettingsError> = serde_json::from_str(&local_var_content).ok();
174        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
175        Err(Error::ResponseError(local_var_error))
176    }
177}
178
179/// Removes the specified Request Settings object.
180pub async fn delete_request_settings(configuration: &mut configuration::Configuration, params: DeleteRequestSettingsParams) -> Result<crate::models::InlineResponse200, Error<DeleteRequestSettingsError>> {
181    let local_var_configuration = configuration;
182
183    // unbox the parameters
184    let service_id = params.service_id;
185    let version_id = params.version_id;
186    let request_settings_name = params.request_settings_name;
187
188
189    let local_var_client = &local_var_configuration.client;
190
191    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/request_settings/{request_settings_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, request_settings_name=crate::apis::urlencode(request_settings_name));
192    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
193
194    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
195        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
196    }
197    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
198        let local_var_key = local_var_apikey.key.clone();
199        let local_var_value = match local_var_apikey.prefix {
200            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
201            None => local_var_key,
202        };
203        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
204    };
205
206    let local_var_req = local_var_req_builder.build()?;
207    let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209    if "DELETE" != "GET" && "DELETE" != "HEAD" {
210      let headers = local_var_resp.headers();
211      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
212          Some(v) => v.to_str().unwrap().parse().unwrap(),
213          None => configuration::DEFAULT_RATELIMIT,
214      };
215      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
216          Some(v) => v.to_str().unwrap().parse().unwrap(),
217          None => 0,
218      };
219    }
220
221    let local_var_status = local_var_resp.status();
222    let local_var_content = local_var_resp.text().await?;
223
224    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
225        serde_json::from_str(&local_var_content).map_err(Error::from)
226    } else {
227        let local_var_entity: Option<DeleteRequestSettingsError> = serde_json::from_str(&local_var_content).ok();
228        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
229        Err(Error::ResponseError(local_var_error))
230    }
231}
232
233/// Gets the specified Request Settings object.
234pub async fn get_request_settings(configuration: &mut configuration::Configuration, params: GetRequestSettingsParams) -> Result<crate::models::RequestSettingsResponse, Error<GetRequestSettingsError>> {
235    let local_var_configuration = configuration;
236
237    // unbox the parameters
238    let service_id = params.service_id;
239    let version_id = params.version_id;
240    let request_settings_name = params.request_settings_name;
241
242
243    let local_var_client = &local_var_configuration.client;
244
245    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/request_settings/{request_settings_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, request_settings_name=crate::apis::urlencode(request_settings_name));
246    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
247
248    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
249        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
250    }
251    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
252        let local_var_key = local_var_apikey.key.clone();
253        let local_var_value = match local_var_apikey.prefix {
254            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
255            None => local_var_key,
256        };
257        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
258    };
259
260    let local_var_req = local_var_req_builder.build()?;
261    let local_var_resp = local_var_client.execute(local_var_req).await?;
262
263    if "GET" != "GET" && "GET" != "HEAD" {
264      let headers = local_var_resp.headers();
265      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
266          Some(v) => v.to_str().unwrap().parse().unwrap(),
267          None => configuration::DEFAULT_RATELIMIT,
268      };
269      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
270          Some(v) => v.to_str().unwrap().parse().unwrap(),
271          None => 0,
272      };
273    }
274
275    let local_var_status = local_var_resp.status();
276    let local_var_content = local_var_resp.text().await?;
277
278    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
279        serde_json::from_str(&local_var_content).map_err(Error::from)
280    } else {
281        let local_var_entity: Option<GetRequestSettingsError> = serde_json::from_str(&local_var_content).ok();
282        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
283        Err(Error::ResponseError(local_var_error))
284    }
285}
286
287/// Returns a list of all Request Settings objects for the given service and version.
288pub async fn list_request_settings(configuration: &mut configuration::Configuration, params: ListRequestSettingsParams) -> Result<Vec<crate::models::RequestSettingsResponse>, Error<ListRequestSettingsError>> {
289    let local_var_configuration = configuration;
290
291    // unbox the parameters
292    let service_id = params.service_id;
293    let version_id = params.version_id;
294
295
296    let local_var_client = &local_var_configuration.client;
297
298    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/request_settings", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
299    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
300
301    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
302        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
303    }
304    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
305        let local_var_key = local_var_apikey.key.clone();
306        let local_var_value = match local_var_apikey.prefix {
307            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
308            None => local_var_key,
309        };
310        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
311    };
312
313    let local_var_req = local_var_req_builder.build()?;
314    let local_var_resp = local_var_client.execute(local_var_req).await?;
315
316    if "GET" != "GET" && "GET" != "HEAD" {
317      let headers = local_var_resp.headers();
318      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
319          Some(v) => v.to_str().unwrap().parse().unwrap(),
320          None => configuration::DEFAULT_RATELIMIT,
321      };
322      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
323          Some(v) => v.to_str().unwrap().parse().unwrap(),
324          None => 0,
325      };
326    }
327
328    let local_var_status = local_var_resp.status();
329    let local_var_content = local_var_resp.text().await?;
330
331    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
332        serde_json::from_str(&local_var_content).map_err(Error::from)
333    } else {
334        let local_var_entity: Option<ListRequestSettingsError> = serde_json::from_str(&local_var_content).ok();
335        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
336        Err(Error::ResponseError(local_var_error))
337    }
338}
339
340/// Updates the specified Request Settings object.
341pub async fn update_request_settings(configuration: &mut configuration::Configuration, params: UpdateRequestSettingsParams) -> Result<crate::models::RequestSettingsResponse, Error<UpdateRequestSettingsError>> {
342    let local_var_configuration = configuration;
343
344    // unbox the parameters
345    let service_id = params.service_id;
346    let version_id = params.version_id;
347    let request_settings_name = params.request_settings_name;
348    let action = params.action;
349    let default_host = params.default_host;
350    let hash_keys = params.hash_keys;
351    let name = params.name;
352    let request_condition = params.request_condition;
353    let xff = params.xff;
354    let bypass_busy_wait = params.bypass_busy_wait;
355    let force_miss = params.force_miss;
356    let force_ssl = params.force_ssl;
357    let geo_headers = params.geo_headers;
358    let max_stale_age = params.max_stale_age;
359    let timer_support = params.timer_support;
360
361
362    let local_var_client = &local_var_configuration.client;
363
364    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/request_settings/{request_settings_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, request_settings_name=crate::apis::urlencode(request_settings_name));
365    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
366
367    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
368        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
369    }
370    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
371        let local_var_key = local_var_apikey.key.clone();
372        let local_var_value = match local_var_apikey.prefix {
373            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
374            None => local_var_key,
375        };
376        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
377    };
378    let mut local_var_form_params = std::collections::HashMap::new();
379    if let Some(local_var_param_value) = action {
380        local_var_form_params.insert("action", local_var_param_value.to_string());
381    }
382    if let Some(local_var_param_value) = default_host {
383        local_var_form_params.insert("default_host", local_var_param_value.to_string());
384    }
385    if let Some(local_var_param_value) = hash_keys {
386        local_var_form_params.insert("hash_keys", local_var_param_value.to_string());
387    }
388    if let Some(local_var_param_value) = name {
389        local_var_form_params.insert("name", local_var_param_value.to_string());
390    }
391    if let Some(local_var_param_value) = request_condition {
392        local_var_form_params.insert("request_condition", local_var_param_value.to_string());
393    }
394    if let Some(local_var_param_value) = xff {
395        local_var_form_params.insert("xff", local_var_param_value.to_string());
396    }
397    if let Some(local_var_param_value) = bypass_busy_wait {
398        local_var_form_params.insert("bypass_busy_wait", local_var_param_value.to_string());
399    }
400    if let Some(local_var_param_value) = force_miss {
401        local_var_form_params.insert("force_miss", local_var_param_value.to_string());
402    }
403    if let Some(local_var_param_value) = force_ssl {
404        local_var_form_params.insert("force_ssl", local_var_param_value.to_string());
405    }
406    if let Some(local_var_param_value) = geo_headers {
407        local_var_form_params.insert("geo_headers", local_var_param_value.to_string());
408    }
409    if let Some(local_var_param_value) = max_stale_age {
410        local_var_form_params.insert("max_stale_age", local_var_param_value.to_string());
411    }
412    if let Some(local_var_param_value) = timer_support {
413        local_var_form_params.insert("timer_support", local_var_param_value.to_string());
414    }
415    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
416
417    let local_var_req = local_var_req_builder.build()?;
418    let local_var_resp = local_var_client.execute(local_var_req).await?;
419
420    if "PUT" != "GET" && "PUT" != "HEAD" {
421      let headers = local_var_resp.headers();
422      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
423          Some(v) => v.to_str().unwrap().parse().unwrap(),
424          None => configuration::DEFAULT_RATELIMIT,
425      };
426      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
427          Some(v) => v.to_str().unwrap().parse().unwrap(),
428          None => 0,
429      };
430    }
431
432    let local_var_status = local_var_resp.status();
433    let local_var_content = local_var_resp.text().await?;
434
435    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
436        serde_json::from_str(&local_var_content).map_err(Error::from)
437    } else {
438        let local_var_entity: Option<UpdateRequestSettingsError> = serde_json::from_str(&local_var_content).ok();
439        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
440        Err(Error::ResponseError(local_var_error))
441    }
442}
443