use http::headers::{HeaderName, ToHeaderValues};
use crate::http;
use crate::response::Response;
pub struct ResponseBuilder<Body> {
response: Response<Body>,
}
impl ResponseBuilder<Vec<u8>> {
pub fn ok() -> ResponseBuilder<Vec<u8>> {
ResponseBuilder::with_status(http::StatusCode::Ok)
}
pub fn with_status(status: http::StatusCode) -> ResponseBuilder<Vec<u8>> {
let response = Response::new_with_status(status);
ResponseBuilder { response }
}
}
impl<Body> ResponseBuilder<Body> {
pub fn body<NewBody>(self, body: NewBody) -> ResponseBuilder<NewBody> {
let response = self.response.with_body(body);
ResponseBuilder { response }
}
pub fn header(mut self, key: impl Into<HeaderName>, value: impl ToHeaderValues) -> Self {
self.response.insert_header(key, value);
self
}
pub fn build(self) -> Response<Body> {
self.response
}
}