rocket_cors/rocket_cors/type.AllowedOrigins.html

80 lines
14 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="API documentation for the Rust `AllowedOrigins` type in crate `rocket_cors`."><meta name="keywords" content="rust, rustlang, rust-lang, AllowedOrigins"><title>rocket_cors::AllowedOrigins - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc type"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../rocket_cors/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Type Definition AllowedOrigins</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.all">all</a><a href="#method.some">some</a><a href="#method.some_exact">some_exact</a><a href="#method.some_null">some_null</a><a href="#method.some_regex">some_regex</a></div></div><p class='location'><a href='index.html'>rocket_cors</a></p><script>window.sidebarCurrent = {name: 'AllowedOrigins', ty: 'type', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/rocket_cors/lib.rs.html#610' title='goto source code'>[src]</a></span><span class='in-band'>Type Definition <a href='index.html'>rocket_cors</a>::<wbr><a class="type" href=''>AllowedOrigins</a></span></h1><pre class='rust typedef'>type AllowedOrigins = <a class="enum" href="../rocket_cors/enum.AllOrSome.html" title="enum rocket_cors::AllOrSome">AllOrSome</a>&lt;<a class="struct" href="../rocket_cors/struct.Origins.html" title="struct rocket_cors::Origins">Origins</a>&gt;;</pre><div class='docblock'><p>A list of allowed origins. Either Some origins are allowed, or all origins are allowed.</p>
<p>Exact matches are matched exactly with the
<a href="https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin">ASCII Serialization</a>
of the origin.</p>
<p>Regular expressions are tested for matches against the
<a href="https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin">ASCII Serialization</a>
of the origin.</p>
<h1 id="opaque-origins" class="section-header"><a href="#opaque-origins">Opaque Origins</a></h1>
<p>The <a href="https://html.spec.whatwg.org/multipage/origin.html">specification</a> defines an Opaque Origin
as one that cannot be recreated. You can refer to the source code for the <a href="https://docs.rs/url/2.0.0/url/struct.Url.html#method.origin" title="`url::Url::origin`"><code>url::Url::origin</code></a>
method to see how an Opaque Origin is determined. Examples of Opaque origins might include
schemes like <code>file://</code> or Browser specific schemes like <code>&quot;moz-extension://</code> or
<code>chrome-extension://</code>.</p>
<p>Opaque Origins cannot be matched exactly. You must use Regex to match Opaque Origins. If you
attempt to create <a href="../rocket_cors/struct.Cors.html" title="`Cors`"><code>Cors</code></a> from <a href="../rocket_cors/struct.CorsOptions.html" title="`CorsOptions`"><code>CorsOptions</code></a>, you will get an error.</p>
<h1 id="warning-about-regex-expressions" class="section-header"><a href="#warning-about-regex-expressions">Warning about Regex expressions</a></h1>
<p>By default, regex expressions are
<a href="https://docs.rs/regex/1.1.2/regex/struct.RegexSet.html#method.is_match">unanchored</a>.</p>
<p>This means that if the regex does not start with <code>^</code> or <code>\A</code>, or end with <code>$</code> or <code>\z</code>,
then it is permitted to match anywhere in the text. You are encouraged to use the anchors when
crafting your Regex expressions.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">rocket_cors</span>::<span class="ident">AllowedOrigins</span>;
<span class="kw">let</span> <span class="ident">exact</span> <span class="op">=</span> [<span class="string">&quot;https://www.acme.com&quot;</span>];
<span class="kw">let</span> <span class="ident">regex</span> <span class="op">=</span> [<span class="string">&quot;^https://(.+).acme.com$&quot;</span>];
<span class="kw">let</span> <span class="ident">all_origins</span> <span class="op">=</span> <span class="ident">AllowedOrigins</span>::<span class="ident">all</span>();
<span class="kw">let</span> <span class="ident">some_origins</span> <span class="op">=</span> <span class="ident">AllowedOrigins</span>::<span class="ident">some_exact</span>(<span class="kw-2">&amp;</span><span class="ident">exact</span>);
<span class="kw">let</span> <span class="ident">null_origins</span> <span class="op">=</span> <span class="ident">AllowedOrigins</span>::<span class="ident">some_null</span>();
<span class="kw">let</span> <span class="ident">regex_origins</span> <span class="op">=</span> <span class="ident">AllowedOrigins</span>::<span class="ident">some_regex</span>(<span class="kw-2">&amp;</span><span class="ident">regex</span>);
<span class="kw">let</span> <span class="ident">mixed_origins</span> <span class="op">=</span> <span class="ident">AllowedOrigins</span>::<span class="ident">some</span>(<span class="kw-2">&amp;</span><span class="ident">exact</span>, <span class="kw-2">&amp;</span><span class="ident">regex</span>);</pre></div>
</div><h2 id='methods' class='small-section-header'>Methods<a href='#methods' class='anchor'></a></h2><h3 id='impl' class='impl'><code class='in-band'>impl <a class="type" href="../rocket_cors/type.AllowedOrigins.html" title="type rocket_cors::AllowedOrigins">AllowedOrigins</a></code><a href='#impl' class='anchor'></a><a class='srclink' href='../src/rocket_cors/lib.rs.html#612-704' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.some' class="method"><code id='some.v'>pub fn <a href='#method.some' class='fnname'>some</a>&lt;'a, 'b, S1:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;, S2:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;exact: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'a [S1]</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;regex: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;'b [S2]</a><br>) -&gt; Self</code><a class='srclink' href='../src/rocket_cors/lib.rs.html#642-648' title='goto source code'>[src]</a></h4><div class='docblock'><p>Allows some origins, with a mix of exact matches or regex matches</p>
<p>Validation is not performed at this stage, but at a later stage.</p>
<p>Exact matches are matched exactly with the
<a href="https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin">ASCII Serialization</a>
of the origin.</p>
<p>Regular expressions are tested for matches against the
<a href="https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin">ASCII Serialization</a>
of the origin.</p>
<h1 id="opaque-origins-1" class="section-header"><a href="#opaque-origins-1">Opaque Origins</a></h1>
<p>The <a href="https://html.spec.whatwg.org/multipage/origin.html">specification</a> defines an Opaque Origin
as one that cannot be recreated. You can refer to the source code for the <a href="https://docs.rs/url/2.0.0/url/struct.Url.html#method.origin" title="`url::Url::origin`"><code>url::Url::origin</code></a>
method to see how an Opaque Origin is determined. Examples of Opaque origins might include
schemes like <code>file://</code> or Browser specific schemes like <code>&quot;moz-extension://</code> or
<code>chrome-extension://</code>.</p>
<p>Opaque Origins cannot be matched exactly. You must use Regex to match Opaque Origins. If you
attempt to create <a href="../rocket_cors/struct.Cors.html" title="`Cors`"><code>Cors</code></a> from <a href="../rocket_cors/struct.CorsOptions.html" title="`CorsOptions`"><code>CorsOptions</code></a>, you will get an error.</p>
<h1 id="warning-about-regex-expressions-1" class="section-header"><a href="#warning-about-regex-expressions-1">Warning about Regex expressions</a></h1>
<p>By default, regex expressions are
<a href="https://docs.rs/regex/1.1.2/regex/struct.RegexSet.html#method.is_match">unanchored</a>.</p>
<p>This means that if the regex does not start with <code>^</code> or <code>\A</code>, or end with <code>$</code> or <code>\z</code>,
then it is permitted to match anywhere in the text. You are encouraged to use the anchors when
crafting your Regex expressions.</p>
</div><h4 id='method.some_exact' class="method"><code id='some_exact.v'>pub fn <a href='#method.some_exact' class='fnname'>some_exact</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;&gt;(exact: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[S]</a>) -&gt; Self</code><a class='srclink' href='../src/rocket_cors/lib.rs.html#663-668' title='goto source code'>[src]</a></h4><div class='docblock'><p>Allows some <em>exact</em> origins</p>
<p>Validation is not performed at this stage, but at a later stage.</p>
<p>Exact matches are matched exactly with the
<a href="https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin">ASCII Serialization</a>
of the origin.</p>
<h1 id="opaque-origins-2" class="section-header"><a href="#opaque-origins-2">Opaque Origins</a></h1>
<p>The <a href="https://html.spec.whatwg.org/multipage/origin.html">specification</a> defines an Opaque Origin
as one that cannot be recreated. You can refer to the source code for the <a href="https://docs.rs/url/2.0.0/url/struct.Url.html#method.origin" title="`url::Url::origin`"><code>url::Url::origin</code></a>
method to see how an Opaque Origin is determined. Examples of Opaque origins might include
schemes like <code>file://</code> or Browser specific schemes like <code>&quot;moz-extension://</code> or
<code>chrome-extension://</code>.</p>
</div><h4 id='method.some_regex' class="method"><code id='some_regex.v'>pub fn <a href='#method.some_regex' class='fnname'>some_regex</a>&lt;S:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;&gt;(regex: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[S]</a>) -&gt; Self</code><a class='srclink' href='../src/rocket_cors/lib.rs.html#685-690' title='goto source code'>[src]</a></h4><div class='docblock'><p>Allow some regular expression origins</p>
<p>Validation is not performed at this stage, but at a later stage.</p>
<p>Regular expressions are tested for matches against the
<a href="https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin">ASCII Serialization</a>
of the origin.</p>
<h1 id="warning-about-regex-expressions-2" class="section-header"><a href="#warning-about-regex-expressions-2">Warning about Regex expressions</a></h1>
<p>By default, regex expressions are
<a href="https://docs.rs/regex/1.1.2/regex/struct.RegexSet.html#method.is_match">unanchored</a>.</p>
<p>This means that if the regex does not start with <code>^</code> or <code>\A</code>, or end with <code>$</code> or <code>\z</code>,
then it is permitted to match anywhere in the text. You are encouraged to use the anchors when
crafting your Regex expressions.</p>
</div><h4 id='method.some_null' class="method"><code id='some_null.v'>pub fn <a href='#method.some_null' class='fnname'>some_null</a>() -&gt; Self</code><a class='srclink' href='../src/rocket_cors/lib.rs.html#693-698' title='goto source code'>[src]</a></h4><div class='docblock'><p>Allow some <code>null</code> origins</p>
</div><h4 id='method.all' class="method"><code id='all.v'>pub fn <a href='#method.all' class='fnname'>all</a>() -&gt; Self</code><a class='srclink' href='../src/rocket_cors/lib.rs.html#701-703' title='goto source code'>[src]</a></h4><div class='docblock'><p>Allows all origins</p>
</div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "rocket_cors";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>