mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
Fixed keep-alive on response example (#316)
* fixed keep-alive on response example * fixed dead code and unused variable errors
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
// <example>
|
||||
use actix_web::{http, HttpRequest, HttpResponse};
|
||||
|
||||
async fn index(req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.connection_type(http::ConnectionType::Close) // <- Close connection
|
||||
.force_close() // <- Alternative method
|
||||
.finish()
|
||||
async fn index(_req: HttpRequest) -> HttpResponse {
|
||||
let mut resp = HttpResponse::Ok()
|
||||
.force_close() // <- Close connection on HttpResponseBuilder
|
||||
.finish();
|
||||
|
||||
// Alternatively close connection on the HttpResponse struct
|
||||
resp.head_mut().set_connection_type(http::ConnectionType::Close);
|
||||
|
||||
resp
|
||||
}
|
||||
// </example>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub mod keep_alive;
|
||||
pub mod keep_alive_tp;
|
||||
pub mod signals;
|
||||
pub mod ssl;
|
||||
pub mod workers;
|
||||
|
Reference in New Issue
Block a user