2021-12-11 02:01:35 +01:00
<!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 = "../SourceSerif4-Regular.ttf.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../FiraSans-Regular.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../FiraSans-Medium.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../SourceCodePro-Regular.ttf.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../SourceSerif4-Bold.ttf.woff2" > < link rel = "preload" as = "font" type = "font/woff2" crossorigin href = "../SourceCodePro-Semibold.ttf.woff2" > < 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 = "../ayu.css" disabled > < link rel = "stylesheet" type = "text/css" href = "../dark.css" disabled > < link rel = "stylesheet" type = "text/css" href = "../light.css" id = "themeStyle" > < script id = "default-settings" > < / script > < script src = "../storage.js" > < / script > < script src = "../crates.js" > < / script > < script defer src = "../main.js" > < / script >
2022-03-06 00:25:11 +01:00
< noscript > < link rel = "stylesheet" href = "../noscript.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" > ☰ < / button > < a class = "sidebar-logo" href = "../actix_cors/index.html" > < div class = "logo-container" > < img src = "https://actix.rs/img/logo.png" alt = "logo" > < / div >
2022-01-21 21:49:16 +01:00
< / a > < h2 class = "location" > < / h2 >
< / nav >
< nav class = "sidebar" > < a class = "sidebar-logo" href = "../actix_cors/index.html" > < div class = "logo-container" >
2022-01-19 18:10:36 +01:00
< img src = "https://actix.rs/img/logo.png" alt = "logo" > < / div >
2022-03-07 22:06:49 +01:00
< / a > < h2 class = "location" > < a href = "#" > Crate actix_cors< / 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 = "#structs" > Structs< / a > < / li > < li > < a href = "#enums" > Enums< / a > < / li > < / ul > < / div > < / section > < div id = "sidebar-vars" data-name = "actix_cors" 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_cors/index.html" >
2022-01-28 18:20:03 +01:00
< 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" >
2022-02-03 23:36:18 +01:00
< h1 class = "fqn" > < span class = "in-band" > Crate < a class = "mod" href = "#" > actix_cors< / 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_cors/lib.rs.html#1-60" > 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 > Cross-Origin Resource Sharing (CORS) controls for Actix Web.< / p >
2021-03-22 12:49:07 +01:00
< p > This middleware can be applied to both applications and resources. Once built, a
2021-06-27 08:05:12 +02:00
< a href = "struct.Cors.html" title = "Cors" > < code > Cors< / code > < / a > builder can be used as an argument for Actix Web’ s < code > App::wrap()< / code > ,
2021-03-22 12:49:07 +01:00
< code > Scope::wrap()< / code > , or < code > Resource::wrap()< / code > methods.< / p >
< p > This CORS middleware automatically handles < code > OPTIONS< / code > preflight requests.< / p >
2022-02-18 04:35:44 +01:00
< h2 id = "example" > < a href = "#example" > Example< / a > < / h2 >
2021-08-31 00:13:55 +02:00
< div class = "example-wrap" > < pre class = "rust rust-example-rendered" > < code > < span class = "kw" > use< / span > < span class = "ident" > actix_cors::Cors< / span > ;
2021-03-22 12:49:07 +01:00
< span class = "kw" > use< / span > < span class = "ident" > actix_web< / span > ::{< span class = "ident" > get< / span > , < span class = "ident" > http< / span > , < span class = "ident" > web< / span > , < span class = "ident" > App< / span > , < span class = "ident" > HttpRequest< / span > , < span class = "ident" > HttpResponse< / span > , < span class = "ident" > HttpServer< / span > };
< span class = "attribute" > #[< span class = "ident" > get< / span > (< span class = "string" > " /index.html" < / span > )]< / span >
2021-10-11 03:57:28 +02:00
< span class = "kw" > async< / span > < span class = "kw" > fn< / span > < span class = "ident" > index< / span > (< span class = "ident" > req< / span > : < span class = "ident" > HttpRequest< / span > ) -> < span class = "kw-2" > & < / span > < span class = "lifetime" > ' static< / span > < span class = "ident" > str< / span > {
2021-03-22 12:49:07 +01:00
< span class = "string" > " < p> Hello World!< /p> " < / span >
}
2021-04-09 15:42:26 +02:00
< span class = "attribute" > #[< span class = "ident" > actix_web::main< / span > ]< / span >
2021-10-11 03:57:28 +02:00
< span class = "kw" > async< / span > < span class = "kw" > fn< / span > < span class = "ident" > main< / span > () -> < span class = "ident" > std::io::Result< / span > < span class = "op" > < < / span > ()< span class = "op" > > < / span > {
2021-04-09 15:42:26 +02:00
< span class = "ident" > HttpServer::new< / span > (< span class = "op" > |< / span > < span class = "op" > |< / span > {
< span class = "kw" > let< / span > < span class = "ident" > cors< / span > < span class = "op" > =< / span > < span class = "ident" > Cors::default< / span > ()
2021-03-22 12:49:07 +01:00
.< span class = "ident" > allowed_origin< / span > (< span class = "string" > " https://www.rust-lang.org/" < / span > )
.< span class = "ident" > allowed_origin_fn< / span > (< span class = "op" > |< / span > < span class = "ident" > origin< / span > , < span class = "ident" > _req_head< / span > < span class = "op" > |< / span > {
< span class = "ident" > origin< / span > .< span class = "ident" > as_bytes< / span > ().< span class = "ident" > ends_with< / span > (< span class = "string" > b" .rust-lang.org" < / span > )
})
2021-04-09 15:42:26 +02:00
.< span class = "ident" > allowed_methods< / span > (< span class = "macro" > vec!< / span > [< span class = "string" > " GET" < / span > , < span class = "string" > " POST" < / span > ])
.< span class = "ident" > allowed_headers< / span > (< span class = "macro" > vec!< / span > [< span class = "ident" > http::header::AUTHORIZATION< / span > , < span class = "ident" > http::header::ACCEPT< / span > ])
.< span class = "ident" > allowed_header< / span > (< span class = "ident" > http::header::CONTENT_TYPE< / span > )
2021-03-22 12:49:07 +01:00
.< span class = "ident" > max_age< / span > (< span class = "number" > 3600< / span > );
2021-04-09 15:42:26 +02:00
< span class = "ident" > App::new< / span > ()
2021-03-22 12:49:07 +01:00
.< span class = "ident" > wrap< / span > (< span class = "ident" > cors< / span > )
.< span class = "ident" > service< / span > (< span class = "ident" > index< / span > )
})
.< span class = "ident" > bind< / span > ((< span class = "string" > " 127.0.0.1" < / span > , < span class = "number" > 8080< / span > ))< span class = "question-mark" > ?< / span >
.< span class = "ident" > run< / span > ()
.< span class = "kw" > await< / span > ;
< span class = "prelude-val" > Ok< / span > (())
2021-08-31 00:13:55 +02:00
}< / code > < / pre > < / div >
2021-12-11 02:01:35 +01:00
< / div > < / details > < h2 id = "structs" class = "small-section-header" > < a href = "#structs" > Structs< / a > < / h2 >
2021-10-11 03:57:28 +02:00
< 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" > < p > Builder for CORS middleware.< / p >
2021-12-11 02:01:35 +01:00
< / div > < / div > < / div > < h2 id = "enums" class = "small-section-header" > < a href = "#enums" > Enums< / a > < / h2 >
2021-10-11 03:57:28 +02:00
< 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" > < p > Errors that can occur when processing CORS guarded requests.< / p >
2022-03-07 16:34:28 +01:00
< / div > < / div > < / div > < / section > < section id = "search" class = "content hidden" > < / section > < / div > < / main > < div id = "rustdoc-vars" data-root-path = "../" data-current-crate = "actix_cors" data-themes = "ayu,dark,light" data-resource-suffix = "" data-rustdoc-version = "1.61.0-nightly (38a0b81b1 2022-03-06)" > < / div >
2021-06-27 08:05:12 +02:00
< / body > < / html >