CGI helper

34 views
Skip to first unread message

Mike Acton

unread,
Feb 5, 2012, 7:34:25 AM2/5/12
to js...@googlegroups.com
I saw this in an old thread:

Date: Sun, 12 Oct 2008 13:47:34 -0700 (PDT)
From: Shanti Rao <sha...@shantirao.com>

Here's the CGI.js library that I'm working on. It'll show up in the
standard distribution soon.

But no cgi.js in the distribution still. I assume that the httpd project took that over?

Here's a cgi.js helper script for anyone else still wanting to use cgi: 
https://gist.github.com/1745154

It fills _GET and _POST variables PHP-style.

Mike.


Mike Acton

unread,
Feb 12, 2012, 5:29:41 AM2/12/12
to js...@googlegroups.com
Updated to handle  'multipart/form-data'
Client-side example using jquery.form.js
Server-side example that just echos the test values back in json: 
Looks like this:

#!/usr/local/bin/jsdb
write('Content-type: application/json\r\n\r\n');

load('../js-lib/http_utils.js');
load('../js-lib/cgi.js');

var cgi = new CGI();
var echo_form = new Object;

if ( cgi._MEDIA_TYPE == 'multipart/form-data' ) {
  echo_form.max_file_size = cgi.MultiPartContent['MAX_FILE_SIZE'];
  echo_form.template_type = cgi.MultiPartContent['template_type'];
  echo_form.import_text = cgi.MultiPartContent['import_text'];
  echo_form.import_file = cgi.MultiPartContent['import_file'];
  echo_form.import_file_requested_name = cgi.findMultiPartHeaderAttr( 'import_file', 'Content-Disposition', 'filename' );
  echo_form.import_file_content_type = cgi.findMultiPartHeaderValue( 'import_file', 'Content-Type' );
}

writeln( JSON.stringify( echo_form ) );
 
Seriously not secure. But might be useful for internal sites.

Mike.


Reply all
Reply to author
Forward
0 new messages