diff options
author | metamuffin <metamuffin@disroot.org> | 2024-10-30 01:04:52 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-10-30 01:04:52 +0100 |
commit | 6cd2149dca23966f64deadbf560b0f238e60da81 (patch) | |
tree | 85689a0aa758314b3fd8bfd6319ee5679ecfcb70 | |
parent | e57fed3acf1bf5c1fd7a40bbfcb77ea440cfb55b (diff) | |
download | gnix-6cd2149dca23966f64deadbf560b0f238e60da81.tar gnix-6cd2149dca23966f64deadbf560b0f238e60da81.tar.bz2 gnix-6cd2149dca23966f64deadbf560b0f238e60da81.tar.zst |
cgi request body
-rw-r--r-- | src/modules/cgi.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/modules/cgi.rs b/src/modules/cgi.rs index b6f1033..14fb19e 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,16 @@ 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()); + + 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 { |