CFG
This commit is contained in:
20
src/cgi.rs
20
src/cgi.rs
@@ -1,10 +1,18 @@
|
||||
#![cfg(any(feature = "cgi", feature = "scgi"))]
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
#[cfg(feature = "cgi")]
|
||||
use tokio::process::Command;
|
||||
use url::Url;
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
#[cfg(feature = "cgi")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(feature = "scgi")]
|
||||
use std::net::ToSocketAddrs;
|
||||
#[cfg(feature = "scgi")]
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
#[cfg(feature = "scgi")]
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
use crate::config;
|
||||
@@ -12,6 +20,7 @@ use crate::conn;
|
||||
use crate::logger;
|
||||
use crate::status::Status;
|
||||
|
||||
#[cfg(any(feature = "cgi", feature = "scgi"))]
|
||||
fn envs(peer_addr: SocketAddr, srv: &config::ServerCfg, url: &url::Url) -> HashMap<String, String> {
|
||||
let mut envs = HashMap::new();
|
||||
envs.insert("GATEWAY_INTERFACE".to_string(), "CGI/1.1".to_string());
|
||||
@@ -40,6 +49,7 @@ fn envs(peer_addr: SocketAddr, srv: &config::ServerCfg, url: &url::Url) -> HashM
|
||||
envs
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "cgi", feature = "scgi"))]
|
||||
fn check(byt: u8, peer_addr: SocketAddr, u: url::Url) -> bool {
|
||||
match byt {
|
||||
49 => {
|
||||
@@ -57,11 +67,12 @@ fn check(byt: u8, peer_addr: SocketAddr, u: url::Url) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(feature = "cgi")]
|
||||
pub async fn cgi(
|
||||
mut con: conn::Connection,
|
||||
srv: &config::ServerCfg,
|
||||
path: PathBuf,
|
||||
url: Url,
|
||||
url: url::Url,
|
||||
) -> Result<(), io::Error> {
|
||||
let mut envs = envs(con.peer_addr, srv, &url);
|
||||
envs.insert("SCRIPT_NAME".to_string(), path.file_name().unwrap().to_str().unwrap().to_string());
|
||||
@@ -112,6 +123,7 @@ pub async fn cgi(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[cfg(feature = "scgi")]
|
||||
pub async fn scgi(addr: String, u: url::Url, mut con: conn::Connection, srv: &config::ServerCfg) -> Result<(), io::Error> {
|
||||
let addr = addr
|
||||
.to_socket_addrs()?
|
||||
|
||||
@@ -19,12 +19,17 @@ pub struct Server {
|
||||
pub key: String,
|
||||
pub cert: String,
|
||||
pub index: Option<String>,
|
||||
#[cfg(feature = "cgi")]
|
||||
pub cgi: Option<bool>,
|
||||
#[cfg(feature = "cgi")]
|
||||
pub cgipath: Option<String>,
|
||||
#[cfg(any(feature = "cgi", feature = "scgi"))]
|
||||
pub cgienv: Option<HashMap<String, String>>,
|
||||
pub usrdir: Option<bool>,
|
||||
#[cfg(feature = "proxy")]
|
||||
pub proxy: Option<HashMap<String, String>>,
|
||||
pub redirect: Option<HashMap<String, String>>,
|
||||
#[cfg(feature = "scgi")]
|
||||
pub scgi: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -176,6 +176,8 @@ async fn handle_connection(
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "proxy")]
|
||||
match &srv.server.proxy {
|
||||
Some(pr) => match url.path_segments().map(|c| c.collect::<Vec<_>>()) {
|
||||
Some(s) => match pr.get(s[0]) {
|
||||
@@ -190,6 +192,7 @@ async fn handle_connection(
|
||||
None => {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "scgi")]
|
||||
match &srv.server.scgi {
|
||||
Some(sc) => {
|
||||
let u = url.path().trim_end_matches("/");
|
||||
@@ -258,6 +261,7 @@ async fn handle_connection(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cgi")]
|
||||
if srv.server.cgi.unwrap_or(false) {
|
||||
match &srv.server.cgipath {
|
||||
Some(c) => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#![cfg(feature = "proxy")]
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
use std::io;
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
Reference in New Issue
Block a user