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