mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
doc fixes
This commit is contained in:
parent
f4e9fc7b6a
commit
2950c90c77
@ -4,8 +4,8 @@
|
||||
- [Getting Started](./qs_2.md)
|
||||
- [Application](./qs_3.md)
|
||||
- [Handler](./qs_4.md)
|
||||
- [State](./qs_6.md)
|
||||
- [Resources and Routes](./qs_5.md)
|
||||
- [Application state](./qs_6.md)
|
||||
- [Request & Response](./qs_7.md)
|
||||
- [WebSockets](./qs_9.md)
|
||||
- [Middlewares](./qs_10.md)
|
||||
|
@ -3,10 +3,10 @@
|
||||
## Individual file
|
||||
|
||||
It is possible to serve static files with custom path pattern and `NamedFile`. To
|
||||
match path tail we can use `.*` regex.
|
||||
match path tail we can use `[.*]` regex.
|
||||
|
||||
```rust
|
||||
extern crate actix_web;
|
||||
# extern crate actix_web;
|
||||
use actix_web::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@ -24,15 +24,16 @@ fn main() {
|
||||
|
||||
## Directory
|
||||
|
||||
To serve files from specific directory and sub-directories `StaticFiles` type could be used.
|
||||
To serve files from specific directory and sub-directories `StaticFiles` could be used.
|
||||
`StaticFiles` could be registered with `Application::route` method.
|
||||
|
||||
```rust
|
||||
extern crate actix_web;
|
||||
# extern crate actix_web;
|
||||
use actix_web::*;
|
||||
|
||||
fn main() {
|
||||
actix_web::Application::default("/")
|
||||
.route("/static", |r| r.h(actix_web::fs::StaticFiles::new(".", true)))
|
||||
Application::default("/")
|
||||
.route("/static", |r| r.h(fs::StaticFiles::new(".", true)))
|
||||
.finish();
|
||||
}
|
||||
```
|
||||
|
@ -1,10 +1,10 @@
|
||||
# HTTP/2
|
||||
|
||||
Actix web automatically upgrades connection to `http/2` if possible.
|
||||
Actix web automatically upgrades connection to *HTTP/2* if possible.
|
||||
|
||||
## Negotiation
|
||||
|
||||
`HTTP/2` protocol over tls without prior knowlage requires
|
||||
*HTTP/2* protocol over tls without prior knowlage requires
|
||||
[tls alpn](https://tools.ietf.org/html/rfc7301). At the moment only
|
||||
`rust-openssl` has support. Turn on `alpn` feature to enable `alpn` negotiation.
|
||||
With enable `alpn` feature `HttpServer` provides
|
||||
@ -27,14 +27,14 @@ fn main() {
|
||||
|
||||
HttpServer::new(
|
||||
Application::default("/")
|
||||
.handler("/index.html", index)
|
||||
.route("/index.html", |r| r.f(index))
|
||||
.serve_tls::<_, ()>("127.0.0.1:8080", pkcs12).unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
Upgrade to `http/2` schema described in
|
||||
Upgrade to *HTTP/2* schema described in
|
||||
[rfc section 3.2](https://http2.github.io/http2-spec/#rfc.section.3.2) is not supported.
|
||||
Starting `http/2` with prior knowledge is supported for both clear text connection
|
||||
Starting *HTTP/2* with prior knowledge is supported for both clear text connection
|
||||
and tls connection. [rfc section 3.4](https://http2.github.io/http2-spec/#rfc.section.3.4)
|
||||
|
||||
Please check [example](https://github.com/actix/actix-web/tree/master/examples/tls)
|
||||
|
@ -1,20 +1,21 @@
|
||||
# Application state
|
||||
|
||||
Application state is shared with all routes within same application.
|
||||
State could be accessed with `HttpRequest::state()` method. It is read-only
|
||||
Application state is shared with all routes and resources within same application.
|
||||
State could be accessed with `HttpRequest::state()` method as a read-only item
|
||||
but interior mutability pattern with `RefCell` could be used to archive state mutability.
|
||||
State could be accessed with `HttpRequest::state()` method or
|
||||
`HttpContext::state()` in case of http actor.
|
||||
State could be accessed with `HttpContext::state()` in case of http actor.
|
||||
State also available to route matching predicates. State is not available
|
||||
to application middlewares, middlewares receives `HttpRequest<()>` object.
|
||||
|
||||
Let's write simple application that uses shared state. We are going to store requests count
|
||||
in the state:
|
||||
|
||||
```rust
|
||||
extern crate actix;
|
||||
extern crate actix_web;
|
||||
|
||||
use std::cell::Cell;
|
||||
# extern crate actix;
|
||||
# extern crate actix_web;
|
||||
#
|
||||
use actix_web::*;
|
||||
use std::cell::Cell;
|
||||
|
||||
// This struct represents state
|
||||
struct AppState {
|
||||
@ -25,7 +26,7 @@ fn index(req: HttpRequest<AppState>) -> String {
|
||||
let count = req.state().counter.get() + 1; // <- get count
|
||||
req.state().counter.set(count); // <- store new count in state
|
||||
|
||||
format!("Request number: {}", count) // <- response with count
|
||||
format!("Request number: {}", count) // <- response with count
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -21,7 +21,7 @@ If other content encoding is selected the compression is enforced for this codec
|
||||
to enable `brotli` response's body compression use `ContentEncoding::Br`:
|
||||
|
||||
```rust
|
||||
extern crate actix_web;
|
||||
# extern crate actix_web;
|
||||
use actix_web::*;
|
||||
|
||||
fn index(req: HttpRequest) -> HttpResponse {
|
||||
@ -39,7 +39,7 @@ type Json<T> where T is the type of a structure to serialize into *JSON*. The
|
||||
type `T` must implement the `Serialize` trait from *serde*.
|
||||
|
||||
```rust
|
||||
extern crate actix_web;
|
||||
# extern crate actix_web;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
use actix_web::*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user