mirror of
https://github.com/actix/actix-extras.git
synced 2025-08-31 19:37:00 +02:00
Deploying to gh-pages from @ 45643d4035
🚀
This commit is contained in:
@@ -650,6 +650,12 @@
|
||||
<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>
|
||||
</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">std</span>::{
|
||||
<span class="ident">collections::HashSet</span>, <span class="ident">convert::TryInto</span>, <span class="ident">error::Error</span> <span class="kw">as</span> <span class="ident">StdError</span>, <span class="ident">iter::FromIterator</span>, <span class="ident">rc::Rc</span>,
|
||||
};
|
||||
@@ -747,6 +753,7 @@
|
||||
|
||||
<span class="ident">expose_headers</span>: <span class="ident">AllOrSome::All</span>,
|
||||
<span class="ident">expose_headers_baked</span>: <span class="prelude-val">None</span>,
|
||||
|
||||
<span class="ident">max_age</span>: <span class="prelude-val">Some</span>(<span class="number">3600</span>),
|
||||
<span class="ident">preflight</span>: <span class="bool-val">true</span>,
|
||||
<span class="ident">send_wildcard</span>: <span class="bool-val">false</span>,
|
||||
@@ -1196,13 +1203,18 @@
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Only call when values are guaranteed to be valid header values and set is not empty.</span>
|
||||
<span class="kw">fn</span> <span class="ident">intersperse_header_values</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>(<span class="ident">val_set</span>: <span class="kw-2">&</span><span class="ident">HashSet</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>) -> <span class="ident">HeaderValue</span>
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn</span> <span class="ident">intersperse_header_values</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>(<span class="ident">val_set</span>: <span class="kw-2">&</span><span class="ident">HashSet</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>) -> <span class="ident">HeaderValue</span>
|
||||
<span class="kw">where</span>
|
||||
<span class="ident">T</span>: <span class="ident">AsRef</span><span class="op"><</span><span class="ident">str</span><span class="op">></span>,
|
||||
{
|
||||
<span class="macro">debug_assert!</span>(
|
||||
<span class="op">!</span><span class="ident">val_set</span>.<span class="ident">is_empty</span>(),
|
||||
<span class="string">"only call `intersperse_header_values` when set is not empty"</span>
|
||||
);
|
||||
|
||||
<span class="ident">val_set</span>
|
||||
.<span class="ident">iter</span>()
|
||||
.<span class="ident">fold</span>(<span class="ident">String::with_capacity</span>(<span class="number">32</span>), <span class="op">|</span><span class="kw-2">mut</span> <span class="ident">acc</span>, <span class="ident">val</span><span class="op">|</span> {
|
||||
.<span class="ident">fold</span>(<span class="ident">String::with_capacity</span>(<span class="number">64</span>), <span class="op">|</span><span class="kw-2">mut</span> <span class="ident">acc</span>, <span class="ident">val</span><span class="op">|</span> {
|
||||
<span class="ident">acc</span>.<span class="ident">push_str</span>(<span class="string">", "</span>);
|
||||
<span class="ident">acc</span>.<span class="ident">push_str</span>(<span class="ident">val</span>.<span class="ident">as_ref</span>());
|
||||
<span class="ident">acc</span>
|
||||
|
@@ -212,7 +212,33 @@
|
||||
<span id="212">212</span>
|
||||
<span id="213">213</span>
|
||||
<span id="214">214</span>
|
||||
</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">std</span>::{<span class="ident">convert::TryInto</span>, <span class="ident">error::Error</span> <span class="kw">as</span> <span class="ident">StdError</span>, <span class="ident">rc::Rc</span>};
|
||||
<span id="215">215</span>
|
||||
<span id="216">216</span>
|
||||
<span id="217">217</span>
|
||||
<span id="218">218</span>
|
||||
<span id="219">219</span>
|
||||
<span id="220">220</span>
|
||||
<span id="221">221</span>
|
||||
<span id="222">222</span>
|
||||
<span id="223">223</span>
|
||||
<span id="224">224</span>
|
||||
<span id="225">225</span>
|
||||
<span id="226">226</span>
|
||||
<span id="227">227</span>
|
||||
<span id="228">228</span>
|
||||
<span id="229">229</span>
|
||||
<span id="230">230</span>
|
||||
<span id="231">231</span>
|
||||
<span id="232">232</span>
|
||||
<span id="233">233</span>
|
||||
<span id="234">234</span>
|
||||
<span id="235">235</span>
|
||||
<span id="236">236</span>
|
||||
<span id="237">237</span>
|
||||
<span id="238">238</span>
|
||||
<span id="239">239</span>
|
||||
<span id="240">240</span>
|
||||
</pre><pre class="rust"><code><span class="kw">use</span> <span class="ident">std</span>::{<span class="ident">collections::HashSet</span>, <span class="ident">convert::TryInto</span>, <span class="ident">error::Error</span> <span class="kw">as</span> <span class="ident">StdError</span>, <span class="ident">rc::Rc</span>};
|
||||
|
||||
<span class="kw">use</span> <span class="ident">actix_web</span>::{
|
||||
<span class="ident">body</span>::{<span class="ident">AnyBody</span>, <span class="ident">MessageBody</span>},
|
||||
@@ -227,7 +253,7 @@
|
||||
<span class="kw">use</span> <span class="ident">futures_util::future</span>::{<span class="ident">ok</span>, <span class="ident">Either</span>, <span class="ident">FutureExt</span> <span class="kw">as</span> <span class="kw">_</span>, <span class="ident">LocalBoxFuture</span>, <span class="ident">Ready</span>, <span class="ident">TryFutureExt</span> <span class="kw">as</span> <span class="kw">_</span>};
|
||||
<span class="kw">use</span> <span class="ident">log::debug</span>;
|
||||
|
||||
<span class="kw">use</span> <span class="ident"><span class="kw">crate</span>::Inner</span>;
|
||||
<span class="kw">use</span> <span class="kw">crate</span>::{<span class="ident">builder::intersperse_header_values</span>, <span class="ident">AllOrSome</span>, <span class="ident">Inner</span>};
|
||||
|
||||
<span class="doccomment">/// Service wrapper for Cross-Origin Resource Sharing support.</span>
|
||||
<span class="doccomment">///</span>
|
||||
@@ -292,8 +318,34 @@
|
||||
};
|
||||
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="kw-2">ref</span> <span class="ident">expose</span>) <span class="op">=</span> <span class="ident">inner</span>.<span class="ident">expose_headers_baked</span> {
|
||||
<span class="macro">log::trace!</span>(<span class="string">"exposing selected headers: {:?}"</span>, <span class="ident">expose</span>);
|
||||
|
||||
<span class="ident">res</span>.<span class="ident">headers_mut</span>()
|
||||
.<span class="ident">insert</span>(<span class="ident">header::ACCESS_CONTROL_EXPOSE_HEADERS</span>, <span class="ident">expose</span>.<span class="ident">clone</span>());
|
||||
} <span class="kw">else</span> <span class="kw">if</span> <span class="macro">matches!</span>(<span class="ident">inner</span>.<span class="ident">expose_headers</span>, <span class="ident">AllOrSome::All</span>) {
|
||||
<span class="comment">// intersperse_header_values requires that argument is non-empty</span>
|
||||
<span class="kw">if</span> <span class="op">!</span><span class="ident">res</span>.<span class="ident">request</span>().<span class="ident">headers</span>().<span class="ident">is_empty</span>() {
|
||||
<span class="comment">// extract header names from request</span>
|
||||
<span class="kw">let</span> <span class="ident">expose_all_request_headers</span> <span class="op">=</span> <span class="ident">res</span>
|
||||
.<span class="ident">request</span>()
|
||||
.<span class="ident">headers</span>()
|
||||
.<span class="ident">keys</span>()
|
||||
.<span class="ident">into_iter</span>()
|
||||
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">name</span><span class="op">|</span> <span class="ident">name</span>.<span class="ident">as_str</span>())
|
||||
.<span class="ident">collect</span>::<span class="op"><</span><span class="ident">HashSet</span><span class="op"><</span><span class="kw">_</span><span class="op">></span><span class="op">></span>();
|
||||
|
||||
<span class="comment">// create comma separated string of header names</span>
|
||||
<span class="kw">let</span> <span class="ident">expose_headers_value</span> <span class="op">=</span> <span class="ident">intersperse_header_values</span>(<span class="kw-2">&</span><span class="ident">expose_all_request_headers</span>);
|
||||
|
||||
<span class="macro">log::trace!</span>(
|
||||
<span class="string">"exposing all headers from request: {:?}"</span>,
|
||||
<span class="ident">expose_headers_value</span>
|
||||
);
|
||||
|
||||
<span class="comment">// add header names to expose response header</span>
|
||||
<span class="ident">res</span>.<span class="ident">headers_mut</span>()
|
||||
.<span class="ident">insert</span>(<span class="ident">header::ACCESS_CONTROL_EXPOSE_HEADERS</span>, <span class="ident">expose_headers_value</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">if</span> <span class="ident">inner</span>.<span class="ident">supports_credentials</span> {
|
||||
|
Reference in New Issue
Block a user