mirror of
https://github.com/actix/actix-extras.git
synced 2025-08-31 19:37:00 +02:00
Deploying to gh-pages from @ 798a5d6d0e
🚀
This commit is contained in:
@@ -163,7 +163,7 @@
|
||||
<span class="doccomment">/// # use actix_web_httpauth::headers::authorization::Bearer;</span>
|
||||
<span class="doccomment">/// let credentials = Bearer::new("mF_9.B5f-4.1JqM");</span>
|
||||
<span class="doccomment">/// ```</span>
|
||||
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>(<span class="ident">token</span>: <span class="ident">T</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Bearer</span>
|
||||
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span><span class="op"><</span><span class="ident">T</span><span class="op">></span>(<span class="ident">token</span>: <span class="ident">T</span>) -> <span class="ident">Bearer</span>
|
||||
<span class="kw">where</span>
|
||||
<span class="ident">T</span>: <span class="ident">Into</span><span class="op"><</span><span class="ident">Cow</span><span class="op"><</span><span class="lifetime">'static</span>, <span class="ident">str</span><span class="op">></span><span class="op">></span>,
|
||||
{
|
||||
@@ -173,13 +173,13 @@
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Gets reference to the credentials token.</span>
|
||||
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">token</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span><span class="ident">Cow</span><span class="op"><</span><span class="lifetime">'static</span>, <span class="ident">str</span><span class="op">></span> {
|
||||
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">token</span>(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="kw-2">&</span><span class="ident">Cow</span><span class="op"><</span><span class="lifetime">'static</span>, <span class="ident">str</span><span class="op">></span> {
|
||||
<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">token</span>
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span> <span class="ident">Scheme</span> <span class="kw">for</span> <span class="ident">Bearer</span> {
|
||||
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">header</span>: <span class="kw-2">&</span><span class="ident">HeaderValue</span>) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="self">Self</span>, <span class="ident">ParseError</span><span class="op">></span> {
|
||||
<span class="kw">fn</span> <span class="ident">parse</span>(<span class="ident">header</span>: <span class="kw-2">&</span><span class="ident">HeaderValue</span>) -> <span class="prelude-ty">Result</span><span class="op"><</span><span class="self">Self</span>, <span class="ident">ParseError</span><span class="op">></span> {
|
||||
<span class="comment">// "Bearer *" length</span>
|
||||
<span class="kw">if</span> <span class="ident">header</span>.<span class="ident">len</span>() <span class="op"><</span> <span class="number">8</span> {
|
||||
<span class="kw">return</span> <span class="prelude-val">Err</span>(<span class="ident">ParseError::Invalid</span>);
|
||||
@@ -187,8 +187,8 @@
|
||||
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">parts</span> <span class="op">=</span> <span class="ident">header</span>.<span class="ident">to_str</span>()<span class="question-mark">?</span>.<span class="ident">splitn</span>(<span class="number">2</span>, <span class="string">' '</span>);
|
||||
<span class="kw">match</span> <span class="ident">parts</span>.<span class="ident">next</span>() {
|
||||
<span class="prelude-val">Some</span>(<span class="ident">scheme</span>) <span class="kw">if</span> <span class="ident">scheme</span> <span class="op">=</span><span class="op">=</span> <span class="string">"Bearer"</span> <span class="op">=</span><span class="op">></span> (),
|
||||
<span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="kw">return</span> <span class="prelude-val">Err</span>(<span class="ident">ParseError::MissingScheme</span>),
|
||||
<span class="prelude-val">Some</span>(<span class="ident">scheme</span>) <span class="kw">if</span> <span class="ident">scheme</span> <span class="op">==</span> <span class="string">"Bearer"</span> => (),
|
||||
<span class="kw">_</span> => <span class="kw">return</span> <span class="prelude-val">Err</span>(<span class="ident">ParseError::MissingScheme</span>),
|
||||
}
|
||||
|
||||
<span class="kw">let</span> <span class="ident">token</span> <span class="op">=</span> <span class="ident">parts</span>.<span class="ident">next</span>().<span class="ident">ok_or</span>(<span class="ident">ParseError::Invalid</span>)<span class="question-mark">?</span>;
|
||||
@@ -200,13 +200,13 @@
|
||||
}
|
||||
|
||||
<span class="kw">impl</span> <span class="ident">fmt::Debug</span> <span class="kw">for</span> <span class="ident">Bearer</span> {
|
||||
<span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt::Result</span> {
|
||||
<span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) -> <span class="ident">fmt::Result</span> {
|
||||
<span class="ident">f</span>.<span class="ident">write_fmt</span>(<span class="macro">format_args!</span>(<span class="string">"Bearer ******"</span>))
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span> <span class="ident">fmt::Display</span> <span class="kw">for</span> <span class="ident">Bearer</span> {
|
||||
<span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt::Result</span> {
|
||||
<span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) -> <span class="ident">fmt::Result</span> {
|
||||
<span class="ident">f</span>.<span class="ident">write_fmt</span>(<span class="macro">format_args!</span>(<span class="string">"Bearer {}"</span>, <span class="self">self</span>.<span class="ident">token</span>))
|
||||
}
|
||||
}
|
||||
@@ -214,7 +214,7 @@
|
||||
<span class="kw">impl</span> <span class="ident">IntoHeaderValue</span> <span class="kw">for</span> <span class="ident">Bearer</span> {
|
||||
<span class="kw">type</span> <span class="ident">Error</span> <span class="op">=</span> <span class="ident">InvalidHeaderValue</span>;
|
||||
|
||||
<span class="kw">fn</span> <span class="ident">try_into_value</span>(<span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">HeaderValue</span>, <span class="op"><</span><span class="self">Self</span> <span class="kw">as</span> <span class="ident">IntoHeaderValue</span><span class="op">></span><span class="ident">::Error</span><span class="op">></span> {
|
||||
<span class="kw">fn</span> <span class="ident">try_into_value</span>(<span class="self">self</span>) -> <span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">HeaderValue</span>, <span class="op"><</span><span class="self">Self</span> <span class="kw">as</span> <span class="ident">IntoHeaderValue</span><span class="op">></span><span class="ident">::Error</span><span class="op">></span> {
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="ident">BytesMut::with_capacity</span>(<span class="number">7</span> <span class="op">+</span> <span class="self">self</span>.<span class="ident">token</span>.<span class="ident">len</span>());
|
||||
<span class="ident">buffer</span>.<span class="ident">put</span>(<span class="kw-2">&</span><span class="string">b"Bearer "</span>[..]);
|
||||
<span class="ident">buffer</span>.<span class="ident">extend_from_slice</span>(<span class="self">self</span>.<span class="ident">token</span>.<span class="ident">as_bytes</span>());
|
||||
|
Reference in New Issue
Block a user