From 39f5936787bba25730c4b02d7c17b3f9b94f6522 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 11 Nov 2024 15:59:42 -0800 Subject: [PATCH] Work on the CGI handling. --- __jet.cpp | 11 +++++++++-- __jet.h | 2 ++ tests/post.example | 21 +++++++++++++++++++++ tests/posttest.sh | 5 +++++ tests/testpost.jet | 4 ++++ 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/post.example create mode 100755 tests/posttest.sh create mode 100755 tests/testpost.jet diff --git a/__jet.cpp b/__jet.cpp index 276ca36..275e515 100644 --- a/__jet.cpp +++ b/__jet.cpp @@ -5,14 +5,21 @@ namespace jet { __jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) { - if(variables["cgi"] == "true") { + if(variableDefined("cgi")) + resolveKeyword("cgi"); + if(variables["cgi"] == "true") { coreutils::ZString requestMethod(getenv("REQUEST_METHOD")); if(requestMethod == "POST") { coreutils::ZString contentLength(getenv("CONTENT_LENGTH")); coreutils::ZString contentType(getenv("CONTENT_TYPE")); - + coreutils::MString postdata; + postdata.read(0); + std::cout << postdata << std::endl; + coreutils::IMFRequest request(postdata); + coreutils::IMFMessage message(postdata); + if(contentType == "multipart/form-data") diff --git a/__jet.h b/__jet.h index 5497285..ed2707b 100644 --- a/__jet.h +++ b/__jet.h @@ -3,6 +3,8 @@ #include "Tag.h" #include "ZString.h" +#include "IMFRequest.h" +#include "IMFMessage.h" #include namespace jet { diff --git a/tests/post.example b/tests/post.example new file mode 100644 index 0000000..b40ba69 --- /dev/null +++ b/tests/post.example @@ -0,0 +1,21 @@ +POST /cgi-bin/qtest HTTP/1.1 +Content-Type: multipart/form-data; + boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f +Content-Length: 514 + +--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f +Content-Disposition: form-data; name="datafile1"; filename="r.gif" +Content-Type: image/gif + +GIF87a.............,...........D..; +--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f +Content-Disposition: form-data; name="datafile2"; filename="g.gif" +Content-Type: image/gif + +GIF87a.............,...........D..; +--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f +Content-Disposition: form-data; name="datafile3"; filename="b.gif" +Content-Type: image/gif + +GIF87a.............,...........D..; +--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f-- \ No newline at end of file diff --git a/tests/posttest.sh b/tests/posttest.sh new file mode 100755 index 0000000..bf22782 --- /dev/null +++ b/tests/posttest.sh @@ -0,0 +1,5 @@ +#!/bin/bash +export REQUEST_METHOD=POST +export CONTENT_LENGTH=554 +export CONTENT_TYPE=multipart/form-data +cat post.example | ./testpost.jet diff --git a/tests/testpost.jet b/tests/testpost.jet new file mode 100755 index 0000000..f1f3c2b --- /dev/null +++ b/tests/testpost.jet @@ -0,0 +1,4 @@ +#!../jet-2.0 + + +