add `ConnectionInfo` example

This commit is contained in:
Ibraheem Ahmed 2021-06-22 11:23:00 -04:00 committed by GitHub
parent 39446fe262
commit 68e1ec96ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,26 @@ const X_FORWARDED_HOST: &[u8] = b"x-forwarded-host";
const X_FORWARDED_PROTO: &[u8] = b"x-forwarded-proto"; const X_FORWARDED_PROTO: &[u8] = b"x-forwarded-proto";
/// `HttpRequest` connection information /// `HttpRequest` connection information
///
/// `ConnectionInfo` implements `FromRequest` and extracted in handlers.
///
/// ## Example
///
/// ```
/// use actix_web::{web, App, HttpRequest, HttpResponse, dev::ConnectionInfo};
///
/// async fn index(conn: ConnectionInfo) -> HttpResponse {
/// match conn.host() {
/// "actix.rs" => HttpResponse::Ok().body("Welcome!"),
/// "admin.actix.rs" => HttpResponse::Ok().body("Admin portal."),
/// _ => HttpResponse::NotFound().finish()
/// }
/// }
///
/// fn main() {
/// let app = App::new().route("/", web::get().to(index));
/// }
/// ```
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct ConnectionInfo { pub struct ConnectionInfo {
scheme: String, scheme: String,