From f694a832d51a5c6c6d1c9a4970927a6e20ee2bdd Mon Sep 17 00:00:00 2001
From: Chris Double <chris.double@double.co.nz>
Date: Thu, 17 Jan 2008 16:33:11 +1300
Subject: [PATCH] Fix environment variables and post support in webapps.cgi

---
 extra/webapps/cgi/cgi.factor | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/extra/webapps/cgi/cgi.factor b/extra/webapps/cgi/cgi.factor
index 26b8f31eae..950174a831 100644
--- a/extra/webapps/cgi/cgi.factor
+++ b/extra/webapps/cgi/cgi.factor
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces kernel assocs io.files combinators
 arrays io.launcher io http.server.responders webapps.file
-sequences strings ;
+sequences strings math.parser ;
 IN: webapps.cgi
 
 SYMBOL: cgi-root
@@ -12,6 +12,8 @@ SYMBOL: cgi-root
 : cgi-variables ( name -- assoc )
     #! This needs some work.
     [
+        cgi-root get over path+ "PATH_TRANSLATED" set
+        cgi-root get over path+ "SCRIPT_FILENAME" set
         "SCRIPT_NAME" set
 
         "CGI/1.0" "GATEWAY_INTERFACE" set
@@ -29,13 +31,14 @@ SYMBOL: cgi-root
 
         "method" get >upper "REQUEST_METHOD" set
         "raw-query" get "QUERY_STRING" set
+	"Cookie" "header" get at "HTTP_COOKIE" set 
 
         "User-Agent" header-param "HTTP_USER_AGENT" set
         "Accept" header-param "HTTP_ACCEPT" set
 
         post? [
             "Content-Type" header-param "CONTENT_TYPE" set
-            "raw-response" get length "CONTENT_LENGTH" set
+            "raw-response" get length number>string "CONTENT_LENGTH" set
         ] when
     ] H{ } make-assoc ;
 
@@ -49,8 +52,7 @@ SYMBOL: cgi-root
     "200 CGI output follows" response
     stdio get swap cgi-descriptor <process-stream> [
         post? [
-            "raw-response" get
-            stream-write stream-flush
+            "raw-response" get write flush
         ] when
         stdio get swap (stream-copy)
     ] with-stream ;