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
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
/// <p>A custom response to send to the client. You can define a custom response for rule actions and default web ACL actions that are set to <code>BlockAction</code>.</p>
/// <p>For information about customizing web requests and responses, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html">Customizing web requests and responses in WAF</a> in the <i>WAF Developer Guide</i>.</p>
#[non_exhaustive]
#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
pub struct CustomResponse {
/// <p>The HTTP status code to return to the client.</p>
/// <p>For a list of status codes that you can use in your custom responses, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/customizing-the-response-status-codes.html">Supported status codes for custom response</a> in the <i>WAF Developer Guide</i>.</p>
pub response_code: i32,
/// <p>References the response body that you want WAF to return to the web request client. You can define a custom response for a rule action or a default web ACL action that is set to block. To do this, you first define the response body key and value in the <code>CustomResponseBodies</code> setting for the <code>WebACL</code> or <code>RuleGroup</code> where you want to use it. Then, in the rule action or web ACL default action <code>BlockAction</code> setting, you reference the response body using this key.</p>
pub custom_response_body_key: ::std::option::Option<::std::string::String>,
/// <p>The HTTP headers to use in the response. You can specify any header name except for <code>content-type</code>. Duplicate header names are not allowed.</p>
/// <p>For information about the limits on count and size for custom request and response settings, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/limits.html">WAF quotas</a> in the <i>WAF Developer Guide</i>.</p>
pub response_headers: ::std::option::Option<::std::vec::Vec<crate::types::CustomHttpHeader>>,
}
impl CustomResponse {
/// <p>The HTTP status code to return to the client.</p>
/// <p>For a list of status codes that you can use in your custom responses, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/customizing-the-response-status-codes.html">Supported status codes for custom response</a> in the <i>WAF Developer Guide</i>.</p>
pub fn response_code(&self) -> i32 {
self.response_code
}
/// <p>References the response body that you want WAF to return to the web request client. You can define a custom response for a rule action or a default web ACL action that is set to block. To do this, you first define the response body key and value in the <code>CustomResponseBodies</code> setting for the <code>WebACL</code> or <code>RuleGroup</code> where you want to use it. Then, in the rule action or web ACL default action <code>BlockAction</code> setting, you reference the response body using this key.</p>
pub fn custom_response_body_key(&self) -> ::std::option::Option<&str> {
self.custom_response_body_key.as_deref()
}
/// <p>The HTTP headers to use in the response. You can specify any header name except for <code>content-type</code>. Duplicate header names are not allowed.</p>
/// <p>For information about the limits on count and size for custom request and response settings, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/limits.html">WAF quotas</a> in the <i>WAF Developer Guide</i>.</p>
///
/// If no value was sent for this field, a default will be set. If you want to determine if no value was sent, use `.response_headers.is_none()`.
pub fn response_headers(&self) -> &[crate::types::CustomHttpHeader] {
self.response_headers.as_deref().unwrap_or_default()
}
}
impl CustomResponse {
/// Creates a new builder-style object to manufacture [`CustomResponse`](crate::types::CustomResponse).
pub fn builder() -> crate::types::builders::CustomResponseBuilder {
crate::types::builders::CustomResponseBuilder::default()
}
}
/// A builder for [`CustomResponse`](crate::types::CustomResponse).
#[non_exhaustive]
#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
pub struct CustomResponseBuilder {
pub(crate) response_code: ::std::option::Option<i32>,
pub(crate) custom_response_body_key: ::std::option::Option<::std::string::String>,
pub(crate) response_headers: ::std::option::Option<::std::vec::Vec<crate::types::CustomHttpHeader>>,
}
impl CustomResponseBuilder {
/// <p>The HTTP status code to return to the client.</p>
/// <p>For a list of status codes that you can use in your custom responses, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/customizing-the-response-status-codes.html">Supported status codes for custom response</a> in the <i>WAF Developer Guide</i>.</p>
/// This field is required.
pub fn response_code(mut self, input: i32) -> Self {
self.response_code = ::std::option::Option::Some(input);
self
}
/// <p>The HTTP status code to return to the client.</p>
/// <p>For a list of status codes that you can use in your custom responses, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/customizing-the-response-status-codes.html">Supported status codes for custom response</a> in the <i>WAF Developer Guide</i>.</p>
pub fn set_response_code(mut self, input: ::std::option::Option<i32>) -> Self {
self.response_code = input;
self
}
/// <p>The HTTP status code to return to the client.</p>
/// <p>For a list of status codes that you can use in your custom responses, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/customizing-the-response-status-codes.html">Supported status codes for custom response</a> in the <i>WAF Developer Guide</i>.</p>
pub fn get_response_code(&self) -> &::std::option::Option<i32> {
&self.response_code
}
/// <p>References the response body that you want WAF to return to the web request client. You can define a custom response for a rule action or a default web ACL action that is set to block. To do this, you first define the response body key and value in the <code>CustomResponseBodies</code> setting for the <code>WebACL</code> or <code>RuleGroup</code> where you want to use it. Then, in the rule action or web ACL default action <code>BlockAction</code> setting, you reference the response body using this key.</p>
pub fn custom_response_body_key(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
self.custom_response_body_key = ::std::option::Option::Some(input.into());
self
}
/// <p>References the response body that you want WAF to return to the web request client. You can define a custom response for a rule action or a default web ACL action that is set to block. To do this, you first define the response body key and value in the <code>CustomResponseBodies</code> setting for the <code>WebACL</code> or <code>RuleGroup</code> where you want to use it. Then, in the rule action or web ACL default action <code>BlockAction</code> setting, you reference the response body using this key.</p>
pub fn set_custom_response_body_key(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
self.custom_response_body_key = input;
self
}
/// <p>References the response body that you want WAF to return to the web request client. You can define a custom response for a rule action or a default web ACL action that is set to block. To do this, you first define the response body key and value in the <code>CustomResponseBodies</code> setting for the <code>WebACL</code> or <code>RuleGroup</code> where you want to use it. Then, in the rule action or web ACL default action <code>BlockAction</code> setting, you reference the response body using this key.</p>
pub fn get_custom_response_body_key(&self) -> &::std::option::Option<::std::string::String> {
&self.custom_response_body_key
}
/// Appends an item to `response_headers`.
///
/// To override the contents of this collection use [`set_response_headers`](Self::set_response_headers).
///
/// <p>The HTTP headers to use in the response. You can specify any header name except for <code>content-type</code>. Duplicate header names are not allowed.</p>
/// <p>For information about the limits on count and size for custom request and response settings, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/limits.html">WAF quotas</a> in the <i>WAF Developer Guide</i>.</p>
pub fn response_headers(mut self, input: crate::types::CustomHttpHeader) -> Self {
let mut v = self.response_headers.unwrap_or_default();
v.push(input);
self.response_headers = ::std::option::Option::Some(v);
self
}
/// <p>The HTTP headers to use in the response. You can specify any header name except for <code>content-type</code>. Duplicate header names are not allowed.</p>
/// <p>For information about the limits on count and size for custom request and response settings, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/limits.html">WAF quotas</a> in the <i>WAF Developer Guide</i>.</p>
pub fn set_response_headers(mut self, input: ::std::option::Option<::std::vec::Vec<crate::types::CustomHttpHeader>>) -> Self {
self.response_headers = input;
self
}
/// <p>The HTTP headers to use in the response. You can specify any header name except for <code>content-type</code>. Duplicate header names are not allowed.</p>
/// <p>For information about the limits on count and size for custom request and response settings, see <a href="https://docs.aws.amazon.com/waf/latest/developerguide/limits.html">WAF quotas</a> in the <i>WAF Developer Guide</i>.</p>
pub fn get_response_headers(&self) -> &::std::option::Option<::std::vec::Vec<crate::types::CustomHttpHeader>> {
&self.response_headers
}
/// Consumes the builder and constructs a [`CustomResponse`](crate::types::CustomResponse).
/// This method will fail if any of the following fields are not set:
/// - [`response_code`](crate::types::builders::CustomResponseBuilder::response_code)
pub fn build(self) -> ::std::result::Result<crate::types::CustomResponse, ::aws_smithy_types::error::operation::BuildError> {
::std::result::Result::Ok(crate::types::CustomResponse {
response_code: self.response_code.ok_or_else(|| {
::aws_smithy_types::error::operation::BuildError::missing_field(
"response_code",
"response_code was not specified but it is required when building CustomResponse",
)
})?,
custom_response_body_key: self.custom_response_body_key,
response_headers: self.response_headers,
})
}
}