mirror of https://github.com/fafhrd91/actix-web
Merge remote-tracking branch 'origin/master' into request-timeout
This commit is contained in:
commit
b7e3cdff2e
|
@ -46,3 +46,21 @@ jobs:
|
|||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --workspace --tests --examples --all-features
|
||||
|
||||
lint-docs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
components: rust-docs
|
||||
- name: Check for broken intra-doc links
|
||||
uses: actions-rs/cargo@v1
|
||||
env:
|
||||
RUSTDOCFLAGS: "-D warnings"
|
||||
with:
|
||||
command: doc
|
||||
args: --no-deps --all-features --workspace
|
||||
|
|
|
@ -209,6 +209,7 @@ impl NamedFile {
|
|||
Self::from_file(file, path)
|
||||
}
|
||||
|
||||
#[allow(rustdoc::broken_intra_doc_links)]
|
||||
/// Attempts to open a file asynchronously in read-only mode.
|
||||
///
|
||||
/// When the `experimental-io-uring` crate feature is enabled, this will be async.
|
||||
|
@ -298,9 +299,11 @@ impl NamedFile {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set content encoding for serving this file
|
||||
/// Sets content encoding for this file.
|
||||
///
|
||||
/// Must be used with [`actix_web::middleware::Compress`] to take effect.
|
||||
/// This prevents the `Compress` middleware from modifying the file contents and signals to
|
||||
/// browsers/clients how to decode it. For example, if serving a compressed HTML file (e.g.,
|
||||
/// `index.html.gz`) then use `.set_content_encoding(ContentEncoding::Gzip)`.
|
||||
#[inline]
|
||||
pub fn set_content_encoding(mut self, enc: ContentEncoding) -> Self {
|
||||
self.encoding = Some(enc);
|
||||
|
|
27
src/app.rs
27
src/app.rs
|
@ -236,12 +236,14 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Default service to be used if no matching resource could be found.
|
||||
/// Default service that is invoked when no matching resource could be found.
|
||||
///
|
||||
/// It is possible to use services like `Route` and [`NamedFile`].
|
||||
/// You can use a [`Route`] as default service.
|
||||
///
|
||||
/// [`NamedFile`]: https://docs.rs/actix-files/latest/actix_files/struct.NamedFile.html
|
||||
/// If a default service is not registered, an empty `404 Not Found` response will be sent to
|
||||
/// the client instead.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use actix_web::{web, App, HttpResponse};
|
||||
///
|
||||
|
@ -250,23 +252,8 @@ where
|
|||
/// }
|
||||
///
|
||||
/// let app = App::new()
|
||||
/// .service(
|
||||
/// web::resource("/index.html").route(web::get().to(index)))
|
||||
/// .default_service(
|
||||
/// web::route().to(|| HttpResponse::NotFound()));
|
||||
/// ```
|
||||
///
|
||||
/// It is also possible to use static files as default service.
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::{web, App, HttpResponse};
|
||||
///
|
||||
/// let app = App::new()
|
||||
/// .service(
|
||||
/// web::resource("/index.html").to(|| HttpResponse::Ok()))
|
||||
/// .default_service(
|
||||
/// web::to(|| HttpResponse::NotFound())
|
||||
/// );
|
||||
/// .service(web::resource("/index.html").route(web::get().to(index)))
|
||||
/// .default_service(web::to(|| HttpResponse::NotFound()));
|
||||
/// ```
|
||||
pub fn default_service<F, U>(mut self, svc: F) -> Self
|
||||
where
|
||||
|
|
|
@ -72,7 +72,7 @@ where
|
|||
})))
|
||||
});
|
||||
|
||||
// App config
|
||||
// create App config to pass to child services
|
||||
let mut config = AppService::new(config, default.clone());
|
||||
|
||||
// register services
|
||||
|
|
|
@ -313,8 +313,12 @@ where
|
|||
}
|
||||
|
||||
/// Default service to be used if no matching route could be found.
|
||||
/// By default *405* response get returned. Resource does not use
|
||||
/// default handler from `App` or `Scope`.
|
||||
///
|
||||
/// You can use a [`Route`] as default service.
|
||||
///
|
||||
/// If a default service is not registered, an empty `405 Method Not Allowed` response will be
|
||||
/// sent to the client instead. Unlike [`Scope`](crate::Scope)s, a [`Resource`] does **not**
|
||||
/// inherit its parent's default service.
|
||||
pub fn default_service<F, U>(mut self, f: F) -> Self
|
||||
where
|
||||
F: IntoServiceFactory<U, ServiceRequest>,
|
||||
|
|
|
@ -262,9 +262,10 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
/// Default service to be used if no matching route could be found.
|
||||
/// Default service to be used if no matching resource could be found.
|
||||
///
|
||||
/// If default resource is not registered, app's default resource is being used.
|
||||
/// If a default service is not registered, it will fall back to the default service of
|
||||
/// the parent [`App`](crate::App) (see [`App::default_service`](crate::App::default_service)).
|
||||
pub fn default_service<F, U>(mut self, f: F) -> Self
|
||||
where
|
||||
F: IntoServiceFactory<U, ServiceRequest>,
|
||||
|
|
Loading…
Reference in New Issue