mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-30 18:34:36 +01:00
Deploying to gh-pages from @ 4d77e26e1e
🚀
This commit is contained in:
parent
e72fa4f1b9
commit
8befae2288
@ -6,7 +6,7 @@
|
||||
<img src="https://actix.rs/img/logo.png" alt="logo"></div>
|
||||
</a><h2 class="location"><a href="#">Crate actix_session</a></h2><div class="sidebar-elems"><div class="block"><ul><li class="version">Version 0.6.1</li><li><a id="all-types" href="all.html">All Items</a></li></div></ul><section><div class="block"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li></ul></div></section><div id="sidebar-vars" data-name="actix_session" data-ty="mod" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../actix_session/index.html">
|
||||
<img src="https://actix.rs/img/logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
|
||||
<h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">actix_session</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/actix_session/lib.rs.html#1-586">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Session management for Actix Web.</p>
|
||||
<h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">actix_session</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/actix_session/lib.rs.html#1-679">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Session management for Actix Web.</p>
|
||||
<p>The HTTP protocol, at a first glance, is stateless: the client sends a request, the server
|
||||
parses its content, performs some processing and returns a response. The outcome is only
|
||||
influenced by the provided inputs (i.e. the request content) and whatever state the server
|
||||
|
@ -4,12 +4,12 @@
|
||||
</nav>
|
||||
<nav class="sidebar"><a class="sidebar-logo" href="../actix_session/index.html"><div class="logo-container">
|
||||
<img src="https://actix.rs/img/logo.png" alt="logo"></div>
|
||||
</a><h2 class="location"><a href="#">SessionExt</a></h2><div class="sidebar-elems"><section><div class="block"><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><ul><li><a href="#tymethod.get_session">get_session</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul><li><a href="#impl-SessionExt-for-HttpRequest">HttpRequest</a></li><li><a href="#impl-SessionExt-for-ServiceRequest">ServiceRequest</a></li><li><a href="#impl-SessionExt-for-ServiceResponse">ServiceResponse</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div></section><h2 class="location"><a href="index.html">In actix_session</a></h2><div id="sidebar-vars" data-name="SessionExt" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../actix_session/index.html">
|
||||
</a><h2 class="location"><a href="#">SessionExt</a></h2><div class="sidebar-elems"><section><div class="block"><h3 class="sidebar-title"><a href="#required-methods">Required Methods</a></h3><ul><li><a href="#tymethod.get_session">get_session</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul><li><a href="#impl-SessionExt-for-GuardContext%3C%27a%3E">GuardContext<'a></a></li><li><a href="#impl-SessionExt-for-HttpRequest">HttpRequest</a></li><li><a href="#impl-SessionExt-for-ServiceRequest">ServiceRequest</a></li><li><a href="#impl-SessionExt-for-ServiceResponse">ServiceResponse</a></li></ul></div><div class="block"><h3 class="sidebar-title"><a href="#implementors">Implementors</a></h3></div></section><h2 class="location"><a href="index.html">In actix_session</a></h2><div id="sidebar-vars" data-name="SessionExt" data-ty="trait" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../actix_session/index.html">
|
||||
<img src="https://actix.rs/img/logo.png" alt="logo"></a><nav class="sub"><div class="theme-picker hidden"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"><img width="22" height="22" alt="Pick another theme!" src="../brush.svg"></button><div id="theme-choices" role="menu"></div></div><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><button type="button" id="help-button" title="help">?</button><a id="settings-menu" href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></form></nav></div><section id="main-content" class="content"><div class="main-heading">
|
||||
<h1 class="fqn"><span class="in-band">Trait <a href="index.html">actix_session</a>::<wbr><a class="trait" href="#">SessionExt</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/actix_session/session_ext.rs.html#10-13">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="docblock item-decl"><pre class="rust trait"><code>pub trait SessionExt {
|
||||
<h1 class="fqn"><span class="in-band">Trait <a href="index.html">actix_session</a>::<wbr><a class="trait" href="#">SessionExt</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/actix_session/session_ext.rs.html#11-14">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="docblock item-decl"><pre class="rust trait"><code>pub trait SessionExt {
|
||||
fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a>;
|
||||
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extract a <a href="struct.Session.html" title="Session"><code>Session</code></a> object from various <code>actix-web</code> types (e.g. <code>HttpRequest</code>,
|
||||
<code>ServiceRequest</code>, <code>ServiceResponse</code>).</p>
|
||||
</div></details><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="tymethod.get_session" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#12">source</a></div><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></div></summary><div class="docblock"><p>Extract a <a href="struct.Session.html" title="Session"><code>Session</code></a> object.</p>
|
||||
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-HttpRequest" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#15-19">source</a></span><a href="#impl-SessionExt-for-HttpRequest" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for HttpRequest</h3></section></summary><div class="impl-items"><section id="method.get_session" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#16-18">source</a></span><a href="#method.get_session" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-ServiceRequest" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#21-25">source</a></span><a href="#impl-SessionExt-for-ServiceRequest" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for ServiceRequest</h3></section></summary><div class="impl-items"><section id="method.get_session-1" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#22-24">source</a></span><a href="#method.get_session-1" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-ServiceResponse" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#27-31">source</a></span><a href="#impl-SessionExt-for-ServiceResponse" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for ServiceResponse</h3></section></summary><div class="impl-items"><section id="method.get_session-2" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#28-30">source</a></span><a href="#method.get_session-2" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><script type="text/javascript" src="../implementors/actix_session/trait.SessionExt.js" async></script></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="actix_session" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.61.0-nightly (63b8f01bb 2022-03-24)" ></div>
|
||||
</div></details><h2 id="required-methods" class="small-section-header">Required methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle" open><summary><div id="tymethod.get_session" class="method has-srclink"><div class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#13">source</a></div><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></div></summary><div class="docblock"><p>Extract a <a href="struct.Session.html" title="Session"><code>Session</code></a> object.</p>
|
||||
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-HttpRequest" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#16-20">source</a></span><a href="#impl-SessionExt-for-HttpRequest" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for HttpRequest</h3></section></summary><div class="impl-items"><section id="method.get_session" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#17-19">source</a></span><a href="#method.get_session" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-ServiceRequest" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#22-26">source</a></span><a href="#impl-SessionExt-for-ServiceRequest" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for ServiceRequest</h3></section></summary><div class="impl-items"><section id="method.get_session-1" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#23-25">source</a></span><a href="#method.get_session-1" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-ServiceResponse" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#28-32">source</a></span><a href="#impl-SessionExt-for-ServiceResponse" class="anchor"></a><h3 class="code-header in-band">impl <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for ServiceResponse</h3></section></summary><div class="impl-items"><section id="method.get_session-2" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#29-31">source</a></span><a href="#method.get_session-2" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-SessionExt-for-GuardContext%3C%27a%3E" class="impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#34-38">source</a></span><a href="#impl-SessionExt-for-GuardContext%3C%27a%3E" class="anchor"></a><h3 class="code-header in-band">impl<'a> <a class="trait" href="trait.SessionExt.html" title="trait actix_session::SessionExt">SessionExt</a> for GuardContext<'a></h3></section></summary><div class="impl-items"><section id="method.get_session-3" class="method trait-impl has-srclink"><span class="rightside"><a class="srclink" href="../src/actix_session/session_ext.rs.html#35-37">source</a></span><a href="#method.get_session-3" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.get_session" class="fnname">get_session</a>(&self) -> <a class="struct" href="struct.Session.html" title="struct actix_session::Session">Session</a></h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div class="item-list" id="implementors-list"></div><script type="text/javascript" src="../implementors/actix_session/trait.SessionExt.js" async></script></section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="actix_session" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.61.0-nightly (63b8f01bb 2022-03-24)" ></div>
|
||||
</body></html>
|
@ -591,6 +591,99 @@
|
||||
<span id="584">584</span>
|
||||
<span id="585">585</span>
|
||||
<span id="586">586</span>
|
||||
<span id="587">587</span>
|
||||
<span id="588">588</span>
|
||||
<span id="589">589</span>
|
||||
<span id="590">590</span>
|
||||
<span id="591">591</span>
|
||||
<span id="592">592</span>
|
||||
<span id="593">593</span>
|
||||
<span id="594">594</span>
|
||||
<span id="595">595</span>
|
||||
<span id="596">596</span>
|
||||
<span id="597">597</span>
|
||||
<span id="598">598</span>
|
||||
<span id="599">599</span>
|
||||
<span id="600">600</span>
|
||||
<span id="601">601</span>
|
||||
<span id="602">602</span>
|
||||
<span id="603">603</span>
|
||||
<span id="604">604</span>
|
||||
<span id="605">605</span>
|
||||
<span id="606">606</span>
|
||||
<span id="607">607</span>
|
||||
<span id="608">608</span>
|
||||
<span id="609">609</span>
|
||||
<span id="610">610</span>
|
||||
<span id="611">611</span>
|
||||
<span id="612">612</span>
|
||||
<span id="613">613</span>
|
||||
<span id="614">614</span>
|
||||
<span id="615">615</span>
|
||||
<span id="616">616</span>
|
||||
<span id="617">617</span>
|
||||
<span id="618">618</span>
|
||||
<span id="619">619</span>
|
||||
<span id="620">620</span>
|
||||
<span id="621">621</span>
|
||||
<span id="622">622</span>
|
||||
<span id="623">623</span>
|
||||
<span id="624">624</span>
|
||||
<span id="625">625</span>
|
||||
<span id="626">626</span>
|
||||
<span id="627">627</span>
|
||||
<span id="628">628</span>
|
||||
<span id="629">629</span>
|
||||
<span id="630">630</span>
|
||||
<span id="631">631</span>
|
||||
<span id="632">632</span>
|
||||
<span id="633">633</span>
|
||||
<span id="634">634</span>
|
||||
<span id="635">635</span>
|
||||
<span id="636">636</span>
|
||||
<span id="637">637</span>
|
||||
<span id="638">638</span>
|
||||
<span id="639">639</span>
|
||||
<span id="640">640</span>
|
||||
<span id="641">641</span>
|
||||
<span id="642">642</span>
|
||||
<span id="643">643</span>
|
||||
<span id="644">644</span>
|
||||
<span id="645">645</span>
|
||||
<span id="646">646</span>
|
||||
<span id="647">647</span>
|
||||
<span id="648">648</span>
|
||||
<span id="649">649</span>
|
||||
<span id="650">650</span>
|
||||
<span id="651">651</span>
|
||||
<span id="652">652</span>
|
||||
<span id="653">653</span>
|
||||
<span id="654">654</span>
|
||||
<span id="655">655</span>
|
||||
<span id="656">656</span>
|
||||
<span id="657">657</span>
|
||||
<span id="658">658</span>
|
||||
<span id="659">659</span>
|
||||
<span id="660">660</span>
|
||||
<span id="661">661</span>
|
||||
<span id="662">662</span>
|
||||
<span id="663">663</span>
|
||||
<span id="664">664</span>
|
||||
<span id="665">665</span>
|
||||
<span id="666">666</span>
|
||||
<span id="667">667</span>
|
||||
<span id="668">668</span>
|
||||
<span id="669">669</span>
|
||||
<span id="670">670</span>
|
||||
<span id="671">671</span>
|
||||
<span id="672">672</span>
|
||||
<span id="673">673</span>
|
||||
<span id="674">674</span>
|
||||
<span id="675">675</span>
|
||||
<span id="676">676</span>
|
||||
<span id="677">677</span>
|
||||
<span id="678">678</span>
|
||||
<span id="679">679</span>
|
||||
</pre><pre class="rust"><code><span class="doccomment">//! Session management for Actix Web.</span>
|
||||
<span class="doccomment">//!</span>
|
||||
<span class="doccomment">//! The HTTP protocol, at a first glance, is stateless: the client sends a request, the server</span>
|
||||
@ -786,13 +879,14 @@
|
||||
<span class="kw-2">*</span><span class="ident">policy</span>,
|
||||
)
|
||||
.<span class="kw">await</span>;
|
||||
<span class="ident">acceptance_tests::guard</span>(<span class="ident">store_builder</span>.<span class="ident">clone</span>(), <span class="kw-2">*</span><span class="ident">policy</span>).<span class="kw">await</span>;
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">mod</span> <span class="ident">acceptance_tests</span> {
|
||||
<span class="kw">use</span> <span class="ident">actix_web</span>::{
|
||||
<span class="ident">dev::Service</span>,
|
||||
<span class="ident">middleware</span>, <span class="ident">test</span>,
|
||||
<span class="ident">guard</span>, <span class="ident">middleware</span>, <span class="ident">test</span>,
|
||||
<span class="ident">web</span>::{<span class="self">self</span>, <span class="ident">get</span>, <span class="ident">post</span>, <span class="ident">resource</span>, <span class="ident">Bytes</span>},
|
||||
<span class="ident">App</span>, <span class="ident">HttpResponse</span>, <span class="prelude-ty">Result</span>,
|
||||
};
|
||||
@ -802,7 +896,7 @@
|
||||
|
||||
<span class="kw">use</span> <span class="kw">crate</span>::{
|
||||
<span class="ident">middleware::SessionLength</span>, <span class="ident">storage::SessionStore</span>, <span class="ident">test_helpers::key</span>,
|
||||
<span class="ident">CookieContentSecurity</span>, <span class="ident">Session</span>, <span class="ident">SessionMiddleware</span>,
|
||||
<span class="ident">CookieContentSecurity</span>, <span class="ident">Session</span>, <span class="ident">SessionExt</span>, <span class="ident">SessionMiddleware</span>,
|
||||
};
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">async</span> <span class="kw">fn</span> <span class="ident">basic_workflow</span><span class="op"><</span><span class="ident">F</span>, <span class="ident">Store</span><span class="op">></span>(
|
||||
@ -901,6 +995,91 @@
|
||||
<span class="macro">assert_eq!</span>(<span class="ident">cookie_2</span>.<span class="ident">max_age</span>(), <span class="prelude-val">Some</span>(<span class="ident">Duration::seconds</span>(<span class="number">60</span>)));
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">async</span> <span class="kw">fn</span> <span class="ident">guard</span><span class="op"><</span><span class="ident">F</span>, <span class="ident">Store</span><span class="op">></span>(<span class="ident">store_builder</span>: <span class="ident">F</span>, <span class="ident">policy</span>: <span class="ident">CookieContentSecurity</span>)
|
||||
<span class="kw">where</span>
|
||||
<span class="ident">Store</span>: <span class="ident">SessionStore</span> <span class="op">+</span> <span class="lifetime">'static</span>,
|
||||
<span class="ident">F</span>: <span class="ident">Fn</span>() -> <span class="ident">Store</span> <span class="op">+</span> <span class="ident">Clone</span> <span class="op">+</span> <span class="ident">Send</span> <span class="op">+</span> <span class="lifetime">'static</span>,
|
||||
{
|
||||
<span class="kw">let</span> <span class="ident">srv</span> <span class="op">=</span> <span class="ident">actix_test::start</span>(<span class="kw">move</span> <span class="op">|</span><span class="op">|</span> {
|
||||
<span class="ident">App::new</span>()
|
||||
.<span class="ident">wrap</span>(
|
||||
<span class="ident">SessionMiddleware::builder</span>(<span class="ident">store_builder</span>(), <span class="ident">key</span>())
|
||||
.<span class="ident">cookie_name</span>(<span class="string">"test-session"</span>.<span class="ident">into</span>())
|
||||
.<span class="ident">cookie_content_security</span>(<span class="ident">policy</span>)
|
||||
.<span class="ident">session_length</span>(<span class="ident">SessionLength::Predetermined</span> {
|
||||
<span class="ident">max_session_length</span>: <span class="prelude-val">Some</span>(<span class="ident">time::Duration::days</span>(<span class="number">7</span>)),
|
||||
})
|
||||
.<span class="ident">build</span>(),
|
||||
)
|
||||
.<span class="ident">wrap</span>(<span class="ident">middleware::Logger::default</span>())
|
||||
.<span class="ident">service</span>(<span class="ident">resource</span>(<span class="string">"/"</span>).<span class="ident">route</span>(<span class="ident">get</span>().<span class="ident">to</span>(<span class="ident">index</span>)))
|
||||
.<span class="ident">service</span>(<span class="ident">resource</span>(<span class="string">"/do_something"</span>).<span class="ident">route</span>(<span class="ident">post</span>().<span class="ident">to</span>(<span class="ident">do_something</span>)))
|
||||
.<span class="ident">service</span>(<span class="ident">resource</span>(<span class="string">"/login"</span>).<span class="ident">route</span>(<span class="ident">post</span>().<span class="ident">to</span>(<span class="ident">login</span>)))
|
||||
.<span class="ident">service</span>(<span class="ident">resource</span>(<span class="string">"/logout"</span>).<span class="ident">route</span>(<span class="ident">post</span>().<span class="ident">to</span>(<span class="ident">logout</span>)))
|
||||
.<span class="ident">service</span>(
|
||||
<span class="ident">web::scope</span>(<span class="string">"/protected"</span>)
|
||||
.<span class="ident">guard</span>(<span class="ident">guard::fn_guard</span>(<span class="op">|</span><span class="ident">g</span><span class="op">|</span> {
|
||||
<span class="ident">g</span>.<span class="ident">get_session</span>().<span class="ident">get</span>::<span class="op"><</span><span class="ident">String</span><span class="op">></span>(<span class="string">"user_id"</span>).<span class="ident">unwrap</span>().<span class="ident">is_some</span>()
|
||||
}))
|
||||
.<span class="ident">service</span>(<span class="ident">resource</span>(<span class="string">"/count"</span>).<span class="ident">route</span>(<span class="ident">get</span>().<span class="ident">to</span>(<span class="ident">count</span>))),
|
||||
)
|
||||
});
|
||||
|
||||
<span class="comment">// Step 1: GET without session info</span>
|
||||
<span class="comment">// - response should be a unsuccessful status</span>
|
||||
<span class="kw">let</span> <span class="ident">req_1</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">get</span>(<span class="string">"/protected/count"</span>).<span class="ident">send</span>();
|
||||
<span class="kw">let</span> <span class="ident">resp_1</span> <span class="op">=</span> <span class="ident">req_1</span>.<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="macro">assert!</span>(<span class="op">!</span><span class="ident">resp_1</span>.<span class="ident">status</span>().<span class="ident">is_success</span>());
|
||||
|
||||
<span class="comment">// Step 2: POST to login</span>
|
||||
<span class="comment">// - set-cookie actix-session will be in response (session cookie #1)</span>
|
||||
<span class="comment">// - updates session state: {"counter": 0, "user_id": "ferris"}</span>
|
||||
<span class="kw">let</span> <span class="ident">req_2</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">post</span>(<span class="string">"/login"</span>).<span class="ident">send_json</span>(<span class="kw-2">&</span><span class="macro">json!</span>({<span class="string">"user_id"</span>: <span class="string">"ferris"</span>}));
|
||||
<span class="kw">let</span> <span class="ident">resp_2</span> <span class="op">=</span> <span class="ident">req_2</span>.<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">cookie_1</span> <span class="op">=</span> <span class="ident">resp_2</span>
|
||||
.<span class="ident">cookies</span>()
|
||||
.<span class="ident">unwrap</span>()
|
||||
.<span class="ident">clone</span>()
|
||||
.<span class="ident">into_iter</span>()
|
||||
.<span class="ident">find</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span>.<span class="ident">name</span>() <span class="op">==</span> <span class="string">"test-session"</span>)
|
||||
.<span class="ident">unwrap</span>();
|
||||
|
||||
<span class="comment">// Step 3: POST to do_something</span>
|
||||
<span class="comment">// - adds new session state: {"counter": 1, "user_id": "ferris" }</span>
|
||||
<span class="comment">// - set-cookie actix-session should be in response (session cookie #2)</span>
|
||||
<span class="comment">// - response should be: {"counter": 1, "user_id": None}</span>
|
||||
<span class="kw">let</span> <span class="ident">req_3</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">post</span>(<span class="string">"/do_something"</span>).<span class="ident">cookie</span>(<span class="ident">cookie_1</span>.<span class="ident">clone</span>()).<span class="ident">send</span>();
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">resp_3</span> <span class="op">=</span> <span class="ident">req_3</span>.<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">result_3</span> <span class="op">=</span> <span class="ident">resp_3</span>.<span class="ident">json</span>::<span class="op"><</span><span class="ident">IndexResponse</span><span class="op">></span>().<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="macro">assert_eq!</span>(
|
||||
<span class="ident">result_3</span>,
|
||||
<span class="ident">IndexResponse</span> {
|
||||
<span class="ident">user_id</span>: <span class="prelude-val">Some</span>(<span class="string">"ferris"</span>.<span class="ident">into</span>()),
|
||||
<span class="ident">counter</span>: <span class="number">1</span>
|
||||
}
|
||||
);
|
||||
<span class="kw">let</span> <span class="ident">cookie_2</span> <span class="op">=</span> <span class="ident">resp_3</span>
|
||||
.<span class="ident">cookies</span>()
|
||||
.<span class="ident">unwrap</span>()
|
||||
.<span class="ident">clone</span>()
|
||||
.<span class="ident">into_iter</span>()
|
||||
.<span class="ident">find</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span>.<span class="ident">name</span>() <span class="op">==</span> <span class="string">"test-session"</span>)
|
||||
.<span class="ident">unwrap</span>();
|
||||
|
||||
<span class="comment">// Step 4: GET using a existing user id</span>
|
||||
<span class="comment">// - response should be: {"counter": 3, "user_id": "ferris"}</span>
|
||||
<span class="kw">let</span> <span class="ident">req_4</span> <span class="op">=</span> <span class="ident">srv</span>.<span class="ident">get</span>(<span class="string">"/protected/count"</span>).<span class="ident">cookie</span>(<span class="ident">cookie_2</span>.<span class="ident">clone</span>()).<span class="ident">send</span>();
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">resp_4</span> <span class="op">=</span> <span class="ident">req_4</span>.<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">result_4</span> <span class="op">=</span> <span class="ident">resp_4</span>.<span class="ident">json</span>::<span class="op"><</span><span class="ident">IndexResponse</span><span class="op">></span>().<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="macro">assert_eq!</span>(
|
||||
<span class="ident">result_4</span>,
|
||||
<span class="ident">IndexResponse</span> {
|
||||
<span class="ident">user_id</span>: <span class="prelude-val">Some</span>(<span class="string">"ferris"</span>.<span class="ident">into</span>()),
|
||||
<span class="ident">counter</span>: <span class="number">1</span>
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">async</span> <span class="kw">fn</span> <span class="ident">complex_workflow</span><span class="op"><</span><span class="ident">F</span>, <span class="ident">Store</span><span class="op">></span>(
|
||||
<span class="ident">store_builder</span>: <span class="ident">F</span>,
|
||||
<span class="ident">is_invalidation_supported</span>: <span class="ident">bool</span>,
|
||||
@ -1142,6 +1321,13 @@
|
||||
<span class="prelude-val">Ok</span>(<span class="ident">HttpResponse::Ok</span>().<span class="ident">json</span>(<span class="kw-2">&</span><span class="ident">IndexResponse</span> { <span class="ident">user_id</span>, <span class="ident">counter</span> }))
|
||||
}
|
||||
|
||||
<span class="kw">async</span> <span class="kw">fn</span> <span class="ident">count</span>(<span class="ident">session</span>: <span class="ident">Session</span>) -> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">HttpResponse</span><span class="op">></span> {
|
||||
<span class="kw">let</span> <span class="ident">user_id</span>: <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">String</span><span class="op">></span> <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op"><</span><span class="ident">String</span><span class="op">></span>(<span class="string">"user_id"</span>).<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">counter</span>: <span class="ident">i32</span> <span class="op">=</span> <span class="ident">session</span>.<span class="ident">get</span>::<span class="op"><</span><span class="ident">i32</span><span class="op">></span>(<span class="string">"counter"</span>).<span class="ident">unwrap</span>().<span class="ident">unwrap</span>();
|
||||
|
||||
<span class="prelude-val">Ok</span>(<span class="ident">HttpResponse::Ok</span>().<span class="ident">json</span>(<span class="kw-2">&</span><span class="ident">IndexResponse</span> { <span class="ident">user_id</span>, <span class="ident">counter</span> }))
|
||||
}
|
||||
|
||||
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Deserialize</span>)]</span>
|
||||
<span class="kw">struct</span> <span class="ident">Identity</span> {
|
||||
<span class="ident">user_id</span>: <span class="ident">String</span>,
|
||||
|
@ -36,8 +36,16 @@
|
||||
<span id="29">29</span>
|
||||
<span id="30">30</span>
|
||||
<span id="31">31</span>
|
||||
<span id="32">32</span>
|
||||
<span id="33">33</span>
|
||||
<span id="34">34</span>
|
||||
<span id="35">35</span>
|
||||
<span id="36">36</span>
|
||||
<span id="37">37</span>
|
||||
<span id="38">38</span>
|
||||
</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">actix_web</span>::{
|
||||
<span class="ident">dev</span>::{<span class="ident">ServiceRequest</span>, <span class="ident">ServiceResponse</span>},
|
||||
<span class="ident">guard::GuardContext</span>,
|
||||
<span class="ident">HttpMessage</span>, <span class="ident">HttpRequest</span>,
|
||||
};
|
||||
|
||||
@ -67,6 +75,12 @@
|
||||
<span class="self">self</span>.<span class="ident">request</span>().<span class="ident">get_session</span>()
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="lifetime">'a</span><span class="op">></span> <span class="ident">SessionExt</span> <span class="kw">for</span> <span class="ident">GuardContext</span><span class="op"><</span><span class="lifetime">'a</span><span class="op">></span> {
|
||||
<span class="kw">fn</span> <span class="ident">get_session</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="ident">Session</span> {
|
||||
<span class="ident">Session::get_session</span>(<span class="kw-2">&mut</span> <span class="kw-2">*</span><span class="self">self</span>.<span class="ident">req_data_mut</span>())
|
||||
}
|
||||
}
|
||||
</code></pre></div>
|
||||
</section><section id="search" class="content hidden"></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="actix_session" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.61.0-nightly (63b8f01bb 2022-03-24)" ></div>
|
||||
</body></html>
|
Loading…
Reference in New Issue
Block a user