115 lines
44 KiB
HTML
115 lines
44 KiB
HTML
<!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 `HttpServer` struct in crate `actix_web`."><meta name="keywords" content="rust, rustlang, rust-lang, HttpServer"><title>actix_web::HttpServer - 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 struct"><!--[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">☰</div><a href='../actix_web/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Struct HttpServer</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.addrs">addrs</a><a href="#method.addrs_with_scheme">addrs_with_scheme</a><a href="#method.backlog">backlog</a><a href="#method.bind">bind</a><a href="#method.client_shutdown">client_shutdown</a><a href="#method.client_timeout">client_timeout</a><a href="#method.disable_signals">disable_signals</a><a href="#method.keep_alive">keep_alive</a><a href="#method.listen">listen</a><a href="#method.maxconn">maxconn</a><a href="#method.maxconnrate">maxconnrate</a><a href="#method.new">new</a><a href="#method.run">run</a><a href="#method.server_hostname">server_hostname</a><a href="#method.shutdown_timeout">shutdown_timeout</a><a href="#method.start">start</a><a href="#method.system_exit">system_exit</a><a href="#method.workers">workers</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-RefUnwindSafe">!RefUnwindSafe</a><a href="#impl-Send">Send</a><a href="#impl-Sync">!Sync</a><a href="#impl-Unpin">Unpin</a><a href="#impl-UnwindSafe">!UnwindSafe</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow<T></a><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a><a href="#impl-From%3CT%3E">From<T></a><a href="#impl-Into%3CU%3E">Into<U></a><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a><a href="#impl-TryInto%3CU%3E">TryInto<U></a><a href="#impl-VZip%3CV%3E">VZip<V></a></div></div><p class='location'><a href='index.html'>actix_web</a></p><script>window.sidebarCurrent = {name: 'HttpServer', ty: 'struct', 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"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled 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'>−</span>]</a></span><a class='srclink' href='../src/actix_web/server.rs.html#51-69' title='goto source code'>[src]</a></span><span class='in-band'>Struct <a href='index.html'>actix_web</a>::<wbr><a class="struct" href=''>HttpServer</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct HttpServer<F, I, S, B> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> I + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + 'static,<br> I: <a class="trait" href="../actix_service/trait.IntoNewService.html" title="trait actix_service::IntoNewService">IntoNewService</a><S>,<br> S: <a class="trait" href="../actix_service/trait.NewService.html" title="trait actix_service::NewService">NewService</a><Config = <a class="struct" href="../actix_server_config/struct.ServerConfig.html" title="struct actix_server_config::ServerConfig">ServerConfig</a>, Request = <a class="struct" href="../actix_http/request/struct.Request.html" title="struct actix_http::request::Request">Request</a>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Error" title="type actix_service::NewService::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.InitError" title="type actix_service::NewService::InitError">InitError</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Response" title="type actix_service::NewService::Response">Response</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="../actix_web/web/struct.HttpResponse.html" title="struct actix_web::web::HttpResponse">Response</a><B>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Service" title="type actix_service::NewService::Service">Service</a>: 'static,<br> B: <a class="trait" href="../actix_web/dev/trait.MessageBody.html" title="trait actix_web::dev::MessageBody">MessageBody</a>, </span> { /* fields omitted */ }</pre></div><div class='docblock'><p>An HTTP Server.</p>
|
||
<p>Create new http server with application factory.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>;
|
||
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">web</span>, <span class="ident">App</span>, <span class="ident">HttpResponse</span>, <span class="ident">HttpServer</span>};
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span>()<span class="op">></span> {
|
||
<span class="kw">let</span> <span class="ident">sys</span> <span class="op">=</span> <span class="ident">actix_rt</span>::<span class="ident">System</span>::<span class="ident">new</span>(<span class="string">"example"</span>); <span class="comment">// <- create Actix runtime</span>
|
||
|
||
<span class="ident">HttpServer</span>::<span class="ident">new</span>(
|
||
<span class="op">|</span><span class="op">|</span> <span class="ident">App</span>::<span class="ident">new</span>()
|
||
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">"/"</span>).<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>())))
|
||
.<span class="ident">bind</span>(<span class="string">"127.0.0.1:59090"</span>)<span class="question-mark">?</span>
|
||
.<span class="ident">start</span>();
|
||
|
||
<span class="ident">sys</span>.<span class="ident">run</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<F, I, S, B> <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> I + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + 'static,<br> I: <a class="trait" href="../actix_service/trait.IntoNewService.html" title="trait actix_service::IntoNewService">IntoNewService</a><S>,<br> S: <a class="trait" href="../actix_service/trait.NewService.html" title="trait actix_service::NewService">NewService</a><Config = <a class="struct" href="../actix_server_config/struct.ServerConfig.html" title="struct actix_server_config::ServerConfig">ServerConfig</a>, Request = <a class="struct" href="../actix_http/request/struct.Request.html" title="struct actix_http::request::Request">Request</a>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Error" title="type actix_service::NewService::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.InitError" title="type actix_service::NewService::InitError">InitError</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Response" title="type actix_service::NewService::Response">Response</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="../actix_web/web/struct.HttpResponse.html" title="struct actix_web::web::HttpResponse">Response</a><B>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Service" title="type actix_service::NewService::Service">Service</a>: 'static,<br> B: <a class="trait" href="../actix_web/dev/trait.MessageBody.html" title="trait actix_web::dev::MessageBody">MessageBody</a> + 'static, </span></code><a href='#impl' class='anchor'></a><a class='srclink' href='../src/actix_web/server.rs.html#71-500' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.new' class="method"><code id='new.v'>pub fn <a href='#method.new' class='fnname'>new</a>(factory: F) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#83-97' title='goto source code'>[src]</a></h4><div class='docblock'><p>Create new http server with application factory</p>
|
||
</div><h4 id='method.workers' class="method"><code id='workers.v'>pub fn <a href='#method.workers' class='fnname'>workers</a>(self, num: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#103-106' title='goto source code'>[src]</a></h4><div class='docblock'><p>Set number of workers to start.</p>
|
||
<p>By default http server uses number of available logical cpu as threads
|
||
count.</p>
|
||
</div><h4 id='method.backlog' class="method"><code id='backlog.v'>pub fn <a href='#method.backlog' class='fnname'>backlog</a>(self, backlog: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#118-122' title='goto source code'>[src]</a></h4><div class='docblock'><p>Set the maximum number of pending connections.</p>
|
||
<p>This refers to the number of clients that can be waiting to be served.
|
||
Exceeding this number results in the client getting an error when
|
||
attempting to connect. It should only affect servers under significant
|
||
load.</p>
|
||
<p>Generally set in the 64-2048 range. Default value is 2048.</p>
|
||
<p>This method should be called before <code>bind()</code> method call.</p>
|
||
</div><h4 id='method.maxconn' class="method"><code id='maxconn.v'>pub fn <a href='#method.maxconn' class='fnname'>maxconn</a>(self, num: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#130-133' title='goto source code'>[src]</a></h4><div class='docblock'><p>Sets the maximum per-worker number of concurrent connections.</p>
|
||
<p>All socket listeners will stop accepting connections when this limit is reached
|
||
for each worker.</p>
|
||
<p>By default max connections is set to a 25k.</p>
|
||
</div><h4 id='method.maxconnrate' class="method"><code id='maxconnrate.v'>pub fn <a href='#method.maxconnrate' class='fnname'>maxconnrate</a>(self, num: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#141-144' title='goto source code'>[src]</a></h4><div class='docblock'><p>Sets the maximum per-worker concurrent connection establish process.</p>
|
||
<p>All listeners will stop accepting connections when this limit is reached. It
|
||
can be used to limit the global SSL CPU usage.</p>
|
||
<p>By default max connections is set to a 256.</p>
|
||
</div><h4 id='method.keep_alive' class="method"><code id='keep_alive.v'>pub fn <a href='#method.keep_alive' class='fnname'>keep_alive</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="enum" href="../actix_http/config/enum.KeepAlive.html" title="enum actix_http::config::KeepAlive">KeepAlive</a>>>(self, val: T) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#149-152' title='goto source code'>[src]</a></h4><div class='docblock'><p>Set server keep-alive setting.</p>
|
||
<p>By default keep alive is set to a 5 seconds.</p>
|
||
</div><h4 id='method.client_timeout' class="method"><code id='client_timeout.v'>pub fn <a href='#method.client_timeout' class='fnname'>client_timeout</a>(self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#163-166' title='goto source code'>[src]</a></h4><div class='docblock'><p>Set server client timeout in milliseconds for first request.</p>
|
||
<p>Defines a timeout for reading client request header. If a client does not transmit
|
||
the entire set headers within this time, the request is terminated with
|
||
the 408 (Request Time-out) error.</p>
|
||
<p>To disable timeout set value to 0.</p>
|
||
<p>By default client timeout is set to 5000 milliseconds.</p>
|
||
</div><h4 id='method.client_shutdown' class="method"><code id='client_shutdown.v'>pub fn <a href='#method.client_shutdown' class='fnname'>client_shutdown</a>(self, val: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#176-179' title='goto source code'>[src]</a></h4><div class='docblock'><p>Set server connection shutdown timeout in milliseconds.</p>
|
||
<p>Defines a timeout for shutdown connection. If a shutdown procedure does not complete
|
||
within this time, the request is dropped.</p>
|
||
<p>To disable timeout set value to 0.</p>
|
||
<p>By default client timeout is set to 5000 milliseconds.</p>
|
||
</div><h4 id='method.server_hostname' class="method"><code id='server_hostname.v'>pub fn <a href='#method.server_hostname' class='fnname'>server_hostname</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>>>(self, val: T) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#186-189' title='goto source code'>[src]</a></h4><div class='docblock'><p>Set server host name.</p>
|
||
<p>Host name is used by application router as a hostname for url
|
||
generation. Check [ConnectionInfo](./dev/struct.ConnectionInfo.
|
||
html#method.host) documentation for more information.</p>
|
||
</div><h4 id='method.system_exit' class="method"><code id='system_exit.v'>pub fn <a href='#method.system_exit' class='fnname'>system_exit</a>(self) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#192-195' title='goto source code'>[src]</a></h4><div class='docblock'><p>Stop actix system.</p>
|
||
</div><h4 id='method.disable_signals' class="method"><code id='disable_signals.v'>pub fn <a href='#method.disable_signals' class='fnname'>disable_signals</a>(self) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#198-201' title='goto source code'>[src]</a></h4><div class='docblock'><p>Disable signal handling</p>
|
||
</div><h4 id='method.shutdown_timeout' class="method"><code id='shutdown_timeout.v'>pub fn <a href='#method.shutdown_timeout' class='fnname'>shutdown_timeout</a>(self, sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> Self</code><a class='srclink' href='../src/actix_web/server.rs.html#210-213' title='goto source code'>[src]</a></h4><div class='docblock'><p>Timeout for graceful workers shutdown.</p>
|
||
<p>After receiving a stop signal, workers have this much time to finish
|
||
serving requests. Workers still alive after the timeout are force
|
||
dropped.</p>
|
||
<p>By default shutdown timeout sets to 30 seconds.</p>
|
||
</div><h4 id='method.addrs' class="method"><code id='addrs.v'>pub fn <a href='#method.addrs' class='fnname'>addrs</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="enum" href="https://doc.rust-lang.org/nightly/std/net/addr/enum.SocketAddr.html" title="enum std::net::addr::SocketAddr">SocketAddr</a>></code><a class='srclink' href='../src/actix_web/server.rs.html#216-218' title='goto source code'>[src]</a></h4><div class='docblock'><p>Get addresses of bound sockets.</p>
|
||
</div><h4 id='method.addrs_with_scheme' class="method"><code id='addrs_with_scheme.v'>pub fn <a href='#method.addrs_with_scheme' class='fnname'>addrs_with_scheme</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="enum" href="https://doc.rust-lang.org/nightly/std/net/addr/enum.SocketAddr.html" title="enum std::net::addr::SocketAddr">SocketAddr</a>, &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>></code><a class='srclink' href='../src/actix_web/server.rs.html#226-228' title='goto source code'>[src]</a></h4><div class='docblock'><p>Get addresses of bound sockets and the scheme for it.</p>
|
||
<p>This is useful when the server is bound from different sources
|
||
with some sockets listening on http and some listening on https
|
||
and the user should be presented with an enumeration of which
|
||
socket requires which protocol.</p>
|
||
</div><h4 id='method.listen' class="method"><code id='listen.v'>pub fn <a href='#method.listen' class='fnname'>listen</a>(self, lst: <a class="struct" href="https://doc.rust-lang.org/nightly/std/net/tcp/struct.TcpListener.html" title="struct std::net::tcp::TcpListener">TcpListener</a>) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><Self></code><a class='srclink' href='../src/actix_web/server.rs.html#234-255' title='goto source code'>[src]</a></h4><div class='docblock'><p>Use listener for accepting incoming connection requests</p>
|
||
<p>HttpServer does not change any configuration for TcpListener,
|
||
it needs to be configured before passing it to listen() method.</p>
|
||
</div><h4 id='method.bind' class="method"><code id='bind.v'>pub fn <a href='#method.bind' class='fnname'>bind</a><A: <a class="trait" href="https://doc.rust-lang.org/nightly/std/net/addr/trait.ToSocketAddrs.html" title="trait std::net::addr::ToSocketAddrs">ToSocketAddrs</a>>(self, addr: A) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><Self></code><a class='srclink' href='../src/actix_web/server.rs.html#359-367' title='goto source code'>[src]</a></h4><div class='docblock'><p>The socket address to bind</p>
|
||
<p>To bind multiple addresses this method can be called multiple times.</p>
|
||
</div></div><h3 id='impl-1' class='impl'><code class='in-band'>impl<F, I, S, B> <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> I + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + 'static,<br> I: <a class="trait" href="../actix_service/trait.IntoNewService.html" title="trait actix_service::IntoNewService">IntoNewService</a><S>,<br> S: <a class="trait" href="../actix_service/trait.NewService.html" title="trait actix_service::NewService">NewService</a><Config = <a class="struct" href="../actix_server_config/struct.ServerConfig.html" title="struct actix_server_config::ServerConfig">ServerConfig</a>, Request = <a class="struct" href="../actix_http/request/struct.Request.html" title="struct actix_http::request::Request">Request</a>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Error" title="type actix_service::NewService::Error">Error</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="../actix_web/error/struct.Error.html" title="struct actix_web::error::Error">Error</a>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.InitError" title="type actix_service::NewService::InitError">InitError</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Response" title="type actix_service::NewService::Response">Response</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><<a class="struct" href="../actix_web/web/struct.HttpResponse.html" title="struct actix_web::web::HttpResponse">Response</a><B>>,<br> S::<a class="type" href="../actix_service/trait.NewService.html#associatedtype.Service" title="type actix_service::NewService::Service">Service</a>: 'static,<br> B: <a class="trait" href="../actix_web/dev/trait.MessageBody.html" title="trait actix_web::dev::MessageBody">MessageBody</a>, </span></code><a href='#impl-1' class='anchor'></a><a class='srclink' href='../src/actix_web/server.rs.html#502-565' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.start' class="method"><code id='start.v'>pub fn <a href='#method.start' class='fnname'>start</a>(self) -> <a class="struct" href="../actix_web/dev/struct.Server.html" title="struct actix_web::dev::Server">Server</a></code><a class='srclink' href='../src/actix_web/server.rs.html#536-538' title='goto source code'>[src]</a></h4><div class='docblock'><p>Start listening for incoming connections.</p>
|
||
<p>This method starts number of http workers in separate threads.
|
||
For each address this method starts separate thread which does
|
||
<code>accept()</code> in a loop.</p>
|
||
<p>This methods panics if no socket address can be bound or an <code>Actix</code> system is not yet
|
||
configured.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>;
|
||
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">web</span>, <span class="ident">App</span>, <span class="ident">HttpResponse</span>, <span class="ident">HttpServer</span>};
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span>()<span class="op">></span> {
|
||
<span class="kw">let</span> <span class="ident">sys</span> <span class="op">=</span> <span class="ident">actix_rt</span>::<span class="ident">System</span>::<span class="ident">new</span>(<span class="string">"example"</span>); <span class="comment">// <- create Actix system</span>
|
||
|
||
<span class="ident">HttpServer</span>::<span class="ident">new</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">"/"</span>).<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>())))
|
||
.<span class="ident">bind</span>(<span class="string">"127.0.0.1:0"</span>)<span class="question-mark">?</span>
|
||
.<span class="ident">start</span>();
|
||
<span class="ident">sys</span>.<span class="ident">run</span>() <span class="comment">// <- Run actix system, this method starts all async processes</span>
|
||
}</pre></div>
|
||
</div><h4 id='method.run' class="method"><code id='run.v'>pub fn <a href='#method.run' class='fnname'>run</a>(self) -> <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>></code><a class='srclink' href='../src/actix_web/server.rs.html#560-564' title='goto source code'>[src]</a></h4><div class='docblock'><p>Spawn new thread and start listening for incoming connections.</p>
|
||
<p>This method spawns new thread and starts new actix system. Other than
|
||
that it is similar to <code>start()</code> method. This method blocks.</p>
|
||
<p>This methods panics if no socket addresses get bound.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>;
|
||
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">web</span>, <span class="ident">App</span>, <span class="ident">HttpResponse</span>, <span class="ident">HttpServer</span>};
|
||
|
||
<span class="kw">fn</span> <span class="ident">main</span>() <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span>()<span class="op">></span> {
|
||
<span class="ident">HttpServer</span>::<span class="ident">new</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">App</span>::<span class="ident">new</span>().<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">"/"</span>).<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>())))
|
||
.<span class="ident">bind</span>(<span class="string">"127.0.0.1:0"</span>)<span class="question-mark">?</span>
|
||
.<span class="ident">run</span>()
|
||
}</pre></div>
|
||
</div></div><h2 id='synthetic-implementations' class='small-section-header'>Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a></h2><div id='synthetic-implementations-list'><h3 id='impl-RefUnwindSafe' class='impl'><code class='in-band'>impl<F, I, S, B> !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B></code><a href='#impl-RefUnwindSafe' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Send' class='impl'><code class='in-band'>impl<F, I, S, B> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B> <span class="where fmt-newline">where<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code><a href='#impl-Send' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><code class='in-band'>impl<F, I, S, B> !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B></code><a href='#impl-Sync' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Unpin' class='impl'><code class='in-band'>impl<F, I, S, B> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B> <span class="where fmt-newline">where<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </span></code><a href='#impl-Unpin' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-UnwindSafe' class='impl'><code class='in-band'>impl<F, I, S, B> !<a class="trait" href="https://doc.rust-lang.org/nightly/std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../actix_web/struct.HttpServer.html" title="struct actix_web::HttpServer">HttpServer</a><F, I, S, B></code><a href='#impl-UnwindSafe' class='anchor'></a></h3><div class='impl-items'></div></div><h2 id='blanket-implementations' class='small-section-header'>Blanket Implementations<a href='#blanket-implementations' class='anchor'></a></h2><div id='blanket-implementations-list'><h3 id='impl-Any' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href='#impl-Any' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/any.rs.html#108-112' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.type_id' class="method hidden"><code id='type_id.v'>fn <a href='https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id' class='fnname'>type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/any.rs.html#109-111' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
|
||
</div></div><h3 id='impl-Borrow%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href='#impl-Borrow%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213-217' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow' class="method hidden"><code id='borrow.v'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&</a>T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#214-216' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></div><h3 id='impl-BorrowMut%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href='#impl-BorrowMut%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220-224' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow_mut' class="method hidden"><code id='borrow_mut.v'>fn <a href='https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut' class='fnname'>borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221-223' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></div><h3 id='impl-From%3CT%3E' class='impl'><code class='in-band'>impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</code><a href='#impl-From%3CT%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#564-568' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from' class="method hidden"><code id='from.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(t: T) -> T</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#565-567' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-Into%3CU%3E' class='impl'><code class='in-band'>impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></code><a href='#impl-Into%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#553-560' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.into' class="method hidden"><code id='into.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into' class='fnname'>into</a>(self) -> U</code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#557-559' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-TryFrom%3CU%3E' class='impl'><code class='in-band'>impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></code><a href='#impl-TryFrom%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#601-610' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error' class="type"><code id='Error.t'>type <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error' class="type">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div><h4 id='method.try_from' class="method hidden"><code id='try_from.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from' class='fnname'>try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#607-609' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-TryInto%3CU%3E' class='impl'><code class='in-band'>impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></code><a href='#impl-TryInto%3CU%3E' class='anchor'></a><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#587-596' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error-1' class="type"><code id='Error.t-1'>type <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error' class="type">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div><h4 id='method.try_into' class="method hidden"><code id='try_into.v'>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into' class='fnname'>try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></code><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#593-595' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id='impl-VZip%3CV%3E' class='impl'><code class='in-band'>impl<V, T> <a class="trait" href="../ppv_lite86/types/types/trait.VZip.html" title="trait ppv_lite86::types::types::VZip">VZip</a><V> for T <span class="where fmt-newline">where<br> V: <a class="trait" href="../ppv_lite86/types/types/trait.MultiLane.html" title="trait ppv_lite86::types::types::MultiLane">MultiLane</a><T>, </span></code><a href='#impl-VZip%3CV%3E' class='anchor'></a><a class='srclink' href='../src/ppv_lite86/types.rs.html#212-220' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.vzip' class="method hidden"><code id='vzip.v'>fn <a href='../ppv_lite86/types/types/trait.VZip.html#tymethod.vzip' class='fnname'>vzip</a>(self) -> V</code><a class='srclink' href='../src/ppv_lite86/types.rs.html#217-219' title='goto source code'>[src]</a></h4></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "actix_web";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html> |