From 6cd2149dca23966f64deadbf560b0f238e60da81 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 30 Oct 2024 01:04:52 +0100 Subject: cgi request body --- src/modules/cgi.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3-70-g09d2