Added time
This commit is contained in:
26
src/cgi.rs
26
src/cgi.rs
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::io::{self, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::collections::HashMap;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_rustls::server::TlsStream;
|
||||
use url::Url;
|
||||
@@ -9,21 +9,20 @@ use url::Url;
|
||||
use crate::config;
|
||||
use crate::status;
|
||||
use crate::util;
|
||||
use crate::Connection;
|
||||
|
||||
pub async fn cgi(
|
||||
stream: TlsStream<TcpStream>,
|
||||
path: PathBuf,
|
||||
url: Url,
|
||||
cfg: config::Config,
|
||||
) -> Result<(), io::Error> {
|
||||
|
||||
pub async fn cgi(con: Connection, path: PathBuf, url: Url) -> Result<(), io::Error> {
|
||||
let mut envs = HashMap::new();
|
||||
envs.insert("GEMINI_URL", url.as_str());
|
||||
envs.insert("SERVER_NAME", url.host_str().unwrap());
|
||||
envs.insert("SCRIPT_NAME", path.file_name().unwrap().to_str().unwrap());
|
||||
envs.insert("SERVER_PROTOCOL", "GEMINI");
|
||||
// envs.insert("SERVER_PORT", &(cfg.port as str));
|
||||
|
||||
let addr = con.peer_addr.ip().to_string();
|
||||
envs.insert("REMOTE_ADDR", &addr);
|
||||
let port = con.peer_addr.port().to_string();
|
||||
envs.insert("REMOTE_PORT", &port);
|
||||
// envs.insert("SERVER_PORT", con.cfg.port.clone().to_string());
|
||||
|
||||
if let Some(q) = url.query() {
|
||||
envs.insert("QUERY_STRING", q);
|
||||
}
|
||||
@@ -34,10 +33,13 @@ pub async fn cgi(
|
||||
.output()
|
||||
.unwrap();
|
||||
if !cmd.status.success() {
|
||||
util::send(stream, status::Status::CGIError, "CGI Error!", None).await?;
|
||||
util::send_status(con.stream, status::Status::CGIError, "CGI Error!").await?;
|
||||
return Ok(());
|
||||
}
|
||||
let cmd = String::from_utf8(cmd.stdout).unwrap();
|
||||
util::send(stream, status::Status::Success, "text/gemini", Some(cmd)).await?;
|
||||
// if cmd.starts_with("20") {
|
||||
util::send_raw(con.stream, cmd).await?;
|
||||
//util::send_body(stream, status::Status::Success, "text/gemini", Some(cmd)).await?;
|
||||
// }
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user