1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00
actix-extras/actix_cors/index.html
2023-01-07 01:06:41 +00:00

45 lines
7.6 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="Cross-Origin Resource Sharing (CORS) controls for Actix Web."><meta name="keywords" content="rust, rustlang, rust-lang, actix_cors"><title>actix_cors - Rust</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-a67221f24dabeddb.css" id="mainThemeStyle"><link rel="stylesheet" id="themeStyle" href="../static.files/light-4743e13df3dfe8c4.css"><link rel="stylesheet" disabled href="../static.files/dark-0e1b889528bd466b.css"><link rel="stylesheet" disabled href="../static.files/ayu-65289d5d067c7c66.css"><script id="default-settings" ></script><script src="../static.files/storage-d43fa987303ecbbb.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-bc1b32400f872ddb.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../actix_cors/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../actix_cors/index.html">
<img src="https://actix.rs/img/logo.png" alt="logo"></a><h2 class="location"><a href="#">Crate actix_cors</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.6.4</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" 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="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">actix_cors</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/actix_cors/lib.rs.html#1-68">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Cross-Origin Resource Sharing (CORS) controls for Actix Web.</p>
<p>This middleware can be applied to both applications and resources. Once built, a <a href="struct.Cors.html" title="Cors"><code>Cors</code></a>
builder can be used as an argument for Actix Webs <code>App::wrap()</code>, <code>Scope::wrap()</code>, or
<code>Resource::wrap()</code> methods.</p>
<p>This CORS middleware automatically handles <code>OPTIONS</code> preflight requests.</p>
<h2 id="crate-features"><a href="#crate-features">Crate Features</a></h2>
<ul>
<li><code>draft-private-network-access</code>: ⚠️ Unstable. Adds opt-in support for the <a href="https://wicg.github.io/private-network-access">Private Network
Access</a> spec extensions. This feature is unstable since it will follow any breaking changes in
the draft spec until it is finalized.</li>
</ul>
<h2 id="example"><a href="#example">Example</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_cors::Cors;
<span class="kw">use </span>actix_web::{get, http, web, App, HttpRequest, HttpResponse, HttpServer};
<span class="attr">#[get(<span class="string">&quot;/index.html&quot;</span>)]
</span><span class="kw">async fn </span>index(req: HttpRequest) -&gt; <span class="kw-2">&amp;</span><span class="lifetime">&#39;static </span>str {
<span class="string">&quot;&lt;p&gt;Hello World!&lt;/p&gt;&quot;
</span>}
<span class="attr">#[actix_web::main]
</span><span class="kw">async fn </span>main() -&gt; std::io::Result&lt;()&gt; {
HttpServer::new(|| {
<span class="kw">let </span>cors = Cors::default()
.allowed_origin(<span class="string">&quot;https://www.rust-lang.org&quot;</span>)
.allowed_origin_fn(|origin, _req_head| {
origin.as_bytes().ends_with(<span class="string">b&quot;.rust-lang.org&quot;</span>)
})
.allowed_methods(<span class="macro">vec!</span>[<span class="string">&quot;GET&quot;</span>, <span class="string">&quot;POST&quot;</span>])
.allowed_headers(<span class="macro">vec!</span>[http::header::AUTHORIZATION, http::header::ACCEPT])
.allowed_header(http::header::CONTENT_TYPE)
.max_age(<span class="number">3600</span>);
App::new()
.wrap(cors)
.service(index)
})
.bind((<span class="string">&quot;127.0.0.1&quot;</span>, <span class="number">8080</span>))<span class="question-mark">?
</span>.run()
.<span class="kw">await</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Cors.html" title="actix_cors::Cors struct">Cors</a></div><div class="item-right docblock-short">Builder for CORS middleware.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.CorsError.html" title="actix_cors::CorsError enum">CorsError</a></div><div class="item-right docblock-short">Errors that can occur when processing CORS guarded requests.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_cors" data-themes="" data-resource-suffix="" data-rustdoc-version="1.68.0-nightly (0fb8b72ce 2023-01-06)" data-search-js="search-181581080540673f.js" data-settings-js="settings-bebeae96e00e4617.js" data-settings-css="settings-58836c674e2f7bd2.css" ></div></body></html>