mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 18:37:41 +02:00
chore(actix-settings): prepare release 0.8.0
This commit is contained in:
@ -242,11 +242,26 @@ where
|
||||
|
||||
/// Extension trait for applying parsed settings to the server object.
|
||||
pub trait ApplySettings<S>: Sized {
|
||||
/// Apply some settings object value to `self`.
|
||||
#[deprecated = "Prefer `try_apply_settings`."]
|
||||
fn apply_settings(self, settings: &S) -> Self;
|
||||
/// Applies some settings object value to `self`.
|
||||
///
|
||||
/// The default implementation calls [`try_apply_settings()`].
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// May panic if settings are invalid or cannot be applied.
|
||||
///
|
||||
/// [`try_apply_settings()`]: ApplySettings::try_apply_settings().
|
||||
#[deprecated = "Prefer `try_apply_settings()`."]
|
||||
fn apply_settings(self, settings: &S) -> Self {
|
||||
self.try_apply_settings(settings)
|
||||
.expect("Could not apply settings")
|
||||
}
|
||||
|
||||
/// Apply some settings object value to `self`.
|
||||
/// Applies some settings object value to `self`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// May return error if settings are invalid or cannot be applied.
|
||||
fn try_apply_settings(self, settings: &S) -> AsResult<Self>;
|
||||
}
|
||||
|
||||
|
@ -21,35 +21,31 @@ pub struct Tls {
|
||||
}
|
||||
|
||||
impl Tls {
|
||||
/// Generates an [`SslAcceptorBuilder`] with its settings. It is often used for the following method
|
||||
/// [`actix_web::server::HttpServer::bind_openssl`].
|
||||
/// Returns an [`SslAcceptorBuilder`] with the configured settings.
|
||||
///
|
||||
/// The result is often used with [`actix_web::HttpServer::bind_openssl()`].
|
||||
///
|
||||
/// # Example
|
||||
/// ```no_run
|
||||
/// use actix_settings::{ApplySettings, Settings};
|
||||
/// use actix_web::{get, App, HttpServer, Responder};
|
||||
///
|
||||
/// #[get("/")]
|
||||
/// async fn index() -> impl Responder {
|
||||
/// "Hello."
|
||||
/// }
|
||||
/// ```no_run
|
||||
/// use std::io;
|
||||
/// use actix_settings::{ApplySettings as _, Settings};
|
||||
/// use actix_web::{get, web, App, HttpServer, Responder};
|
||||
///
|
||||
/// #[actix_web::main]
|
||||
/// async fn main() -> std::io::Result<()> {
|
||||
/// async fn main() -> io::Result<()> {
|
||||
/// let settings = Settings::from_default_template();
|
||||
///
|
||||
/// HttpServer::new(|| {
|
||||
/// App::new()
|
||||
/// .service(index)
|
||||
/// App::new().service(web::to(|| { "Hello, World!" }))
|
||||
/// })
|
||||
/// .try_apply_settings(&settings)?
|
||||
/// .bind(("127.0.0.1", 8080))?
|
||||
/// .bind_openssl(("127.0.0.1", 8081), settings.actix.tls.get_ssl_acceptor_builder()?)?
|
||||
/// .bind_openssl(("127.0.0.1", 8443), settings.actix.tls.get_ssl_acceptor_builder()?)?
|
||||
/// .run()
|
||||
/// .await
|
||||
/// }
|
||||
/// ```
|
||||
#[allow(rustdoc::broken_intra_doc_links)]
|
||||
pub fn get_ssl_acceptor_builder(&self) -> AsResult<SslAcceptorBuilder> {
|
||||
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?;
|
||||
builder.set_certificate_chain_file(&self.certificate)?;
|
||||
|
Reference in New Issue
Block a user