Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
#![warn(clippy::large_futures)]
|
||||
|
||||
pub mod context;
|
||||
pub mod request;
|
||||
pub mod response;
|
||||
|
||||
pub use form_urlencoded;
|
||||
|
||||
use common::network::ServerInstance;
|
||||
use hyper::StatusCode;
|
||||
use std::{net::IpAddr, sync::Arc};
|
||||
|
||||
pub type HttpRequest = hyper::Request<hyper::body::Incoming>;
|
||||
|
||||
pub struct JsonResponse<T: serde::Serialize> {
|
||||
status: StatusCode,
|
||||
inner: T,
|
||||
no_cache: bool,
|
||||
}
|
||||
|
||||
pub struct HtmlResponse {
|
||||
status: StatusCode,
|
||||
body: String,
|
||||
}
|
||||
|
||||
pub enum HttpResponseBody {
|
||||
Text(String),
|
||||
Binary(Vec<u8>),
|
||||
Stream(http_body_util::combinators::BoxBody<hyper::body::Bytes, hyper::Error>),
|
||||
WebsocketUpgrade(String),
|
||||
Empty,
|
||||
}
|
||||
|
||||
pub struct HttpResponse {
|
||||
status: StatusCode,
|
||||
builder: hyper::http::response::Builder,
|
||||
body: HttpResponseBody,
|
||||
}
|
||||
|
||||
pub struct HttpContext<'x> {
|
||||
pub session: &'x HttpSessionData,
|
||||
pub req: &'x HttpRequest,
|
||||
}
|
||||
|
||||
pub struct HttpSessionData {
|
||||
pub instance: Arc<ServerInstance>,
|
||||
pub local_ip: IpAddr,
|
||||
pub local_port: u16,
|
||||
pub remote_ip: IpAddr,
|
||||
pub remote_port: u16,
|
||||
pub is_tls: bool,
|
||||
pub session_id: u64,
|
||||
}
|
||||
|
||||
pub struct DownloadResponse {
|
||||
pub filename: String,
|
||||
pub content_type: String,
|
||||
pub blob: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct JsonProblemResponse(pub StatusCode);
|
||||
|
||||
impl<T: serde::Serialize> JsonResponse<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
JsonResponse {
|
||||
inner,
|
||||
status: StatusCode::OK,
|
||||
no_cache: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_status(status: StatusCode, inner: T) -> Self {
|
||||
JsonResponse {
|
||||
inner,
|
||||
status,
|
||||
no_cache: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn no_cache(mut self) -> Self {
|
||||
self.no_cache = true;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl HtmlResponse {
|
||||
pub fn new(body: String) -> Self {
|
||||
HtmlResponse {
|
||||
body,
|
||||
status: StatusCode::OK,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_status(status: StatusCode, body: String) -> Self {
|
||||
HtmlResponse { body, status }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToHttpResponse {
|
||||
fn into_http_response(self) -> HttpResponse;
|
||||
}
|
||||
Reference in New Issue
Block a user