mirror of
https://github.com/actix/actix-extras.git
synced 2025-09-02 21:16:37 +02:00
Deploying to gh-pages from @ 8fd166435f
🚀
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `actix-limitation/src/builder.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>builder.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="../../source-script.js"></script><script defer src="../../source-files.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><div class="width-limiter"><nav class="sub"><a class="sub-logo-container" href="../../actix_limitation/index.html">
|
||||
<img src="https://actix.rs/img/logo.png" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><pre class="src-line-numbers"><span id="1">1</span>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `actix-limitation/src/builder.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>builder.rs - source</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-1f7d512b176f0f72.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Bold-124a1ca42af929b6.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ef244fc9943488f7.css" id="mainThemeStyle"><link rel="stylesheet" id="themeStyle" href="../../static.files/light-c11f492748536797.css"><link rel="stylesheet" disabled href="../../static.files/dark-a78f946771c40031.css"><link rel="stylesheet" disabled href="../../static.files/ayu-70b683d68cb31790.css"><script id="default-settings" ></script><script src="../../static.files/storage-d43fa987303ecbbb.js"></script><script defer src="../../static.files/source-script-74087aa2e88f4475.js"></script><script defer src="../../source-files.js"></script><script defer src="../../static.files/main-0dede64717b247ca.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-201a7e04dc4c6fce.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"></nav><main><div class="width-limiter"><nav class="sub"><a class="sub-logo-container" href="../../actix_limitation/index.html">
|
||||
<img src="https://actix.rs/img/logo.png" alt="logo"></a><form class="search-form"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-5ec35bf9ca753509.svg"></a></div></form></nav><section id="main-content" class="content"><div class="example-wrap"><pre class="src-line-numbers"><span id="1">1</span>
|
||||
<span id="2">2</span>
|
||||
<span id="3">3</span>
|
||||
<span id="4">4</span>
|
||||
@@ -172,7 +172,7 @@
|
||||
<span id="171">171</span>
|
||||
</pre><pre class="rust"><code><span class="kw">use </span>std::{borrow::Cow, sync::Arc, time::Duration};
|
||||
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span><span class="kw">use </span>actix_session::SessionExt <span class="kw">as _</span>;
|
||||
<span class="kw">use </span>actix_web::dev::ServiceRequest;
|
||||
<span class="kw">use </span>redis::Client;
|
||||
@@ -180,14 +180,14 @@
|
||||
<span class="kw">use crate</span>::{errors::Error, GetArcBoxKeyFn, Limiter};
|
||||
|
||||
<span class="doccomment">/// Rate limiter builder.
|
||||
</span><span class="attribute">#[derive(Debug)]
|
||||
</span><span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">pub struct </span>Builder {
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) redis_url: String,
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) limit: usize,
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) period: Duration,
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) get_key_fn: <span class="prelude-ty">Option</span><GetArcBoxKeyFn>,
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) cookie_name: Cow<<span class="lifetime">'static</span>, str>,
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) session_key: Cow<<span class="lifetime">'static</span>, str>,
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@
|
||||
<span class="doccomment">/// Sets name of cookie to be sent.
|
||||
///
|
||||
/// This method should not be used in combination of `key_by` as they conflict.
|
||||
</span><span class="attribute">#[deprecated = <span class="string">"Prefer `key_by`."</span>]
|
||||
</span><span class="attr">#[deprecated = <span class="string">"Prefer `key_by`."</span>]
|
||||
</span><span class="kw">pub fn </span>cookie_name(<span class="kw-2">&mut </span><span class="self">self</span>, cookie_name: <span class="kw">impl </span>Into<Cow<<span class="lifetime">'static</span>, str>>) -> <span class="kw-2">&mut </span><span class="self">Self </span>{
|
||||
<span class="kw">if </span><span class="self">self</span>.get_key_fn.is_some() {
|
||||
<span class="macro">panic!</span>(<span class="string">"This method should not be used in combination of get_key as they overwrite each other"</span>)
|
||||
@@ -230,7 +230,7 @@
|
||||
<span class="doccomment">/// Sets session key to be used in backend.
|
||||
///
|
||||
/// This method should not be used in combination of `key_by` as they conflict.
|
||||
</span><span class="attribute">#[deprecated = <span class="string">"Prefer `key_by`."</span>]
|
||||
</span><span class="attr">#[deprecated = <span class="string">"Prefer `key_by`."</span>]
|
||||
#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span><span class="kw">pub fn </span>session_key(<span class="kw-2">&mut </span><span class="self">self</span>, session_key: <span class="kw">impl </span>Into<Cow<<span class="lifetime">'static</span>, str>>) -> <span class="kw-2">&mut </span><span class="self">Self </span>{
|
||||
<span class="kw">if </span><span class="self">self</span>.get_key_fn.is_some() {
|
||||
@@ -250,17 +250,17 @@
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw">let </span>cookie_name = <span class="self">self</span>.cookie_name.clone();
|
||||
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span><span class="kw">let </span>session_key = <span class="self">self</span>.session_key.clone();
|
||||
|
||||
<span class="kw">let </span>closure: GetArcBoxKeyFn = Arc::new(Box::new(<span class="kw">move </span>|req: <span class="kw-2">&</span>ServiceRequest| {
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span><span class="kw">let </span>res = req
|
||||
.get_session()
|
||||
.get(<span class="kw-2">&</span>session_key)
|
||||
.unwrap_or_else(|<span class="kw">_</span>| req.cookie(<span class="kw-2">&</span>cookie_name).map(|c| c.to_string()));
|
||||
|
||||
<span class="attribute">#[cfg(not(feature = <span class="string">"session"</span>))]
|
||||
<span class="attr">#[cfg(not(feature = <span class="string">"session"</span>))]
|
||||
</span><span class="kw">let </span>res = req.cookie(<span class="kw-2">&</span>cookie_name).map(|c| c.to_string());
|
||||
|
||||
res
|
||||
@@ -277,11 +277,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attribute">#[cfg(test)]
|
||||
<span class="attr">#[cfg(test)]
|
||||
</span><span class="kw">mod </span>tests {
|
||||
<span class="kw">use super</span>::<span class="kw-2">*</span>;
|
||||
|
||||
<span class="attribute">#[test]
|
||||
<span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>test_create_builder() {
|
||||
<span class="kw">let </span>redis_url = <span class="string">"redis://127.0.0.1"</span>;
|
||||
<span class="kw">let </span>period = Duration::from_secs(<span class="number">10</span>);
|
||||
@@ -291,19 +291,19 @@
|
||||
period,
|
||||
get_key_fn: <span class="prelude-val">Some</span>(Arc::new(|<span class="kw">_</span>| <span class="prelude-val">None</span>)),
|
||||
cookie_name: Cow::Owned(<span class="string">"session"</span>.to_string()),
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span>session_key: Cow::Owned(<span class="string">"rate-api"</span>.to_string()),
|
||||
};
|
||||
|
||||
<span class="macro">assert_eq!</span>(builder.redis_url, redis_url);
|
||||
<span class="macro">assert_eq!</span>(builder.limit, <span class="number">100</span>);
|
||||
<span class="macro">assert_eq!</span>(builder.period, period);
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span><span class="macro">assert_eq!</span>(builder.session_key, <span class="string">"rate-api"</span>);
|
||||
<span class="macro">assert_eq!</span>(builder.cookie_name, <span class="string">"session"</span>);
|
||||
}
|
||||
|
||||
<span class="attribute">#[test]
|
||||
<span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>test_create_limiter() {
|
||||
<span class="kw">let </span>redis_url = <span class="string">"redis://127.0.0.1"</span>;
|
||||
<span class="kw">let </span>period = Duration::from_secs(<span class="number">20</span>);
|
||||
@@ -313,7 +313,7 @@
|
||||
period: Duration::from_secs(<span class="number">10</span>),
|
||||
get_key_fn: <span class="prelude-val">Some</span>(Arc::new(|<span class="kw">_</span>| <span class="prelude-val">None</span>)),
|
||||
cookie_name: Cow::Borrowed(<span class="string">"sid"</span>),
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span>session_key: Cow::Borrowed(<span class="string">"key"</span>),
|
||||
};
|
||||
|
||||
@@ -323,7 +323,7 @@
|
||||
<span class="macro">assert_eq!</span>(limiter.period, period);
|
||||
}
|
||||
|
||||
<span class="attribute">#[test]
|
||||
<span class="attr">#[test]
|
||||
#[should_panic = <span class="string">"Redis URL did not parse"</span>]
|
||||
</span><span class="kw">fn </span>test_create_limiter_error() {
|
||||
<span class="kw">let </span>redis_url = <span class="string">"127.0.0.1"</span>;
|
||||
@@ -334,7 +334,7 @@
|
||||
period: Duration::from_secs(<span class="number">10</span>),
|
||||
get_key_fn: <span class="prelude-val">Some</span>(Arc::new(|<span class="kw">_</span>| <span class="prelude-val">None</span>)),
|
||||
cookie_name: Cow::Borrowed(<span class="string">"sid"</span>),
|
||||
<span class="attribute">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
<span class="attr">#[cfg(feature = <span class="string">"session"</span>)]
|
||||
</span>session_key: Cow::Borrowed(<span class="string">"key"</span>),
|
||||
};
|
||||
|
||||
@@ -342,4 +342,4 @@
|
||||
}
|
||||
}
|
||||
</code></pre></div>
|
||||
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="actix_limitation" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5e9772042 2022-10-29)" ></div></body></html>
|
||||
</section></div></main><div id="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_limitation" data-themes="" data-resource-suffix="" data-rustdoc-version="1.67.0-nightly (73c9eaf21 2022-11-07)" data-search-js="search-39ee4160c7dc16c9.js" data-settings-js="settings-3a0b9947ba1bd99a.js" data-settings-css="settings-a66f7524084a489a.css" ></div></body></html>
|
Reference in New Issue
Block a user