aboutsummaryrefslogtreecommitdiff
path: root/src/modules/cgi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/cgi.rs')
-rw-r--r--src/modules/cgi.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/modules/cgi.rs b/src/modules/cgi.rs
index b6f1033..9d9372f 100644
--- a/src/modules/cgi.rs
+++ b/src/modules/cgi.rs
@@ -2,7 +2,7 @@ use super::{Node, NodeKind, NodeResponse};
use crate::error::ServiceError;
use anyhow::{anyhow, Result};
use futures::TryStreamExt;
-use http_body_util::{combinators::BoxBody, StreamBody};
+use http_body_util::{combinators::BoxBody, BodyExt, StreamBody};
use hyper::{
body::Frame,
header::{HeaderName, HeaderValue, CONTENT_LENGTH, CONTENT_TYPE},
@@ -10,12 +10,15 @@ use hyper::{
};
use serde::Deserialize;
use serde_yaml::Value;
-use std::{future::Future, path::PathBuf, pin::Pin, process::Stdio, str::FromStr, sync::Arc};
+use std::{
+ future::Future, io::ErrorKind, path::PathBuf, pin::Pin, process::Stdio, str::FromStr, sync::Arc,
+};
use tokio::{
- io::{AsyncBufReadExt, BufReader},
+ io::{copy, AsyncBufReadExt, BufReader, BufWriter},
process::Command,
+ spawn,
};
-use tokio_util::io::ReaderStream;
+use tokio_util::io::{ReaderStream, StreamReader};
use users::get_user_by_name;
pub struct CgiKind;
@@ -107,6 +110,17 @@ impl Node for Cgi {
let mut child = command.spawn()?;
let mut stdout = BufReader::new(child.stdout.take().unwrap());
+ let mut stdin = BufWriter::new(child.stdin.take().unwrap());
+
+ // TODO prevent abuse
+ let mut body = StreamReader::new(
+ request
+ .into_body()
+ .into_data_stream()
+ .map_err(|_| std::io::Error::new(ErrorKind::BrokenPipe, "asd")),
+ );
+ spawn(async move { copy(&mut body, &mut stdin).await });
+
let mut line = String::new();
let mut response = Response::new(());
loop {