mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-03 17:41:30 +02:00
Compare commits
3 Commits
http-test-
...
web-v1.0.0
Author | SHA1 | Date | |
---|---|---|---|
e399e01a22 | |||
d9a62c4bbf | |||
a548b69679 |
@ -11,7 +11,7 @@ Actix web is a simple, pragmatic and extremely fast web framework for Rust.
|
|||||||
* Multipart streams
|
* Multipart streams
|
||||||
* Static assets
|
* Static assets
|
||||||
* SSL support with OpenSSL or Rustls
|
* SSL support with OpenSSL or Rustls
|
||||||
* Middlewares ([Logger, Session, CORS, CSRF, etc](https://actix.rs/docs/middleware/))
|
* Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/))
|
||||||
* Includes an asynchronous [HTTP client](https://actix.rs/actix-web/actix_web/client/index.html)
|
* Includes an asynchronous [HTTP client](https://actix.rs/actix-web/actix_web/client/index.html)
|
||||||
* Supports [Actix actor framework](https://github.com/actix/actix)
|
* Supports [Actix actor framework](https://github.com/actix/actix)
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ Actix web is a simple, pragmatic and extremely fast web framework for Rust.
|
|||||||
* [API Documentation (0.7)](https://docs.rs/actix-web/0.7.19/actix_web/)
|
* [API Documentation (0.7)](https://docs.rs/actix-web/0.7.19/actix_web/)
|
||||||
* [Chat on gitter](https://gitter.im/actix/actix)
|
* [Chat on gitter](https://gitter.im/actix/actix)
|
||||||
* Cargo package: [actix-web](https://crates.io/crates/actix-web)
|
* Cargo package: [actix-web](https://crates.io/crates/actix-web)
|
||||||
* Minimum supported Rust version: 1.32 or later
|
* Minimum supported Rust version: 1.34 or later
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -693,11 +693,12 @@ where
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// read socket into a buf
|
// read socket into a buf
|
||||||
let should_disconnect = if !inner.flags.contains(Flags::READ_DISCONNECT) {
|
let should_disconnect =
|
||||||
read_available(&mut inner.io, &mut inner.read_buf)?
|
if !inner.flags.contains(Flags::READ_DISCONNECT) {
|
||||||
} else {
|
read_available(&mut inner.io, &mut inner.read_buf)?
|
||||||
None
|
} else {
|
||||||
};
|
None
|
||||||
|
};
|
||||||
|
|
||||||
inner.poll_request()?;
|
inner.poll_request()?;
|
||||||
if let Some(true) = should_disconnect {
|
if let Some(true) = should_disconnect {
|
||||||
|
@ -156,4 +156,4 @@ pub fn patch(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||||||
let args = parse_macro_input!(args as syn::AttributeArgs);
|
let args = parse_macro_input!(args as syn::AttributeArgs);
|
||||||
let gen = route::Args::new(&args, input, route::GuardType::Patch);
|
let gen = route::Args::new(&args, input, route::GuardType::Patch);
|
||||||
gen.generate()
|
gen.generate()
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ pub enum GuardType {
|
|||||||
Connect,
|
Connect,
|
||||||
Options,
|
Options,
|
||||||
Trace,
|
Trace,
|
||||||
Patch
|
Patch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for GuardType {
|
impl fmt::Display for GuardType {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use actix_http::HttpService;
|
use actix_http::HttpService;
|
||||||
use actix_http_test::TestServer;
|
use actix_http_test::TestServer;
|
||||||
use actix_web::{http, web::Path, App, HttpResponse, Responder};
|
use actix_web::{http, web::Path, App, HttpResponse, Responder};
|
||||||
use actix_web_codegen::{delete, get, post, put, patch, head, connect, options, trace};
|
use actix_web_codegen::{connect, delete, get, head, options, patch, post, put, trace};
|
||||||
use futures::{future, Future};
|
use futures::{future, Future};
|
||||||
|
|
||||||
#[get("/test")]
|
#[get("/test")]
|
||||||
|
@ -100,6 +100,13 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set application data. Application data could be accessed
|
||||||
|
/// by using `Data<T>` extractor where `T` is data type.
|
||||||
|
pub fn register_data<U: 'static>(mut self, data: Data<U>) -> Self {
|
||||||
|
self.data.push(Box::new(data));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Run external configuration as part of the application building
|
/// Run external configuration as part of the application building
|
||||||
/// process
|
/// process
|
||||||
///
|
///
|
||||||
|
23
src/data.rs
23
src/data.rs
@ -54,7 +54,7 @@ pub(crate) trait DataFactory {
|
|||||||
///
|
///
|
||||||
/// let app = App::new()
|
/// let app = App::new()
|
||||||
/// // Store `MyData` in application storage.
|
/// // Store `MyData` in application storage.
|
||||||
/// .data(data.clone())
|
/// .register_data(data.clone())
|
||||||
/// .service(
|
/// .service(
|
||||||
/// web::resource("/index.html").route(
|
/// web::resource("/index.html").route(
|
||||||
/// web::get().to(index)));
|
/// web::get().to(index)));
|
||||||
@ -130,6 +130,7 @@ impl<T: 'static> DataFactory for Data<T> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use crate::http::StatusCode;
|
use crate::http::StatusCode;
|
||||||
use crate::test::{block_on, init_service, TestRequest};
|
use crate::test::{block_on, init_service, TestRequest};
|
||||||
use crate::{web, App, HttpResponse};
|
use crate::{web, App, HttpResponse};
|
||||||
@ -154,6 +155,26 @@ mod tests {
|
|||||||
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_register_data_extractor() {
|
||||||
|
let mut srv =
|
||||||
|
init_service(App::new().register_data(Data::new(10usize)).service(
|
||||||
|
web::resource("/").to(|_: web::Data<usize>| HttpResponse::Ok()),
|
||||||
|
));
|
||||||
|
|
||||||
|
let req = TestRequest::default().to_request();
|
||||||
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
|
||||||
|
let mut srv =
|
||||||
|
init_service(App::new().register_data(Data::new(10u32)).service(
|
||||||
|
web::resource("/").to(|_: web::Data<usize>| HttpResponse::Ok()),
|
||||||
|
));
|
||||||
|
let req = TestRequest::default().to_request();
|
||||||
|
let resp = block_on(srv.call(req)).unwrap();
|
||||||
|
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_route_data_extractor() {
|
fn test_route_data_extractor() {
|
||||||
let mut srv =
|
let mut srv =
|
||||||
|
@ -32,7 +32,7 @@ ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.1.2"
|
actix-codec = "0.1.2"
|
||||||
actix-rt = "0.2.2"
|
actix-rt = "0.2.2"
|
||||||
actix-service = "0.4.1"
|
actix-service = "0.4.0"
|
||||||
actix-server = "0.5.1"
|
actix-server = "0.5.1"
|
||||||
actix-utils = "0.4.1"
|
actix-utils = "0.4.1"
|
||||||
awc = "0.2.1"
|
awc = "0.2.1"
|
||||||
|
Reference in New Issue
Block a user