use http_body_util::Full;
use hyper::body::{Bytes, Incoming};
use hyper::{Method, Request, Response, StatusCode, Version};
pub fn is_proxy_request(req: &Request<Incoming>) -> bool {
if req.method() == Method::CONNECT {
return true;
}
if req.version() == Version::HTTP_2 {
return false;
}
req.uri().authority().is_some()
}
pub fn fake_404(server_name: &str) -> Response<Full<Bytes>> {
let body = concat!(
"<html>\r\n",
"<head><title>404 Not Found</title></head>\r\n",
"<body>\r\n",
"<center><h1>404 Not Found</h1></center>\r\n",
"<hr><center>nginx/1.24.0</center>\r\n",
"</body>\r\n",
"</html>\r\n",
);
Response::builder()
.status(StatusCode::NOT_FOUND)
.header("Server", server_name)
.header("Content-Type", "text/html")
.header("Content-Length", body.len().to_string())
.body(Full::new(Bytes::from(body)))
.unwrap()
}
pub fn proxy_auth_required(server_name: &str) -> Response<Full<Bytes>> {
Response::builder()
.status(StatusCode::PROXY_AUTHENTICATION_REQUIRED)
.header("Server", server_name)
.header("Proxy-Authenticate", "Basic realm=\"proxy\"")
.header("Content-Length", "0")
.body(Full::new(Bytes::new()))
.unwrap()
}