Esempio n. 1
0
exports.app = function(env) {
    var req = new Request(env),
        res = new Response();
    
    if (req.isPost())
    {
        var params = req.params();
        for (var i in params)
        {
            res.setHeader("Content-Type", "text/plain");
            if (typeof params[i] === "string")
                res.write(i + " => " + params[i] + "\n");
            else
            {
                for (var j in params[i])
                    res.write("> " + j + " => " + params[i][j] + "\n");
            }
        }
    }
    else
    {
        res.write('<form action="" method="post" enctype="multipart/form-data">')
        res.write('<input type="file" name="foo" value="">');
        res.write('<input type="text" name="bar" value="baz">');
        res.write('<input type="submit" value="Upload">');
        res.write('</form>');
    }
    
    return res.finish();
}
Esempio n. 2
0
var commitSession = function(env, jsgiResponse, key, secret){
    var session = env["jsgi.session"];

    if (!session) return jsgiResponse;

    var sessionData = JSON.stringify(session);

    var digest = sha.hash(sessionData + secret).decodeToString(64);

    // do not serialize if the session is not dirty.
    if (digest == env["jsgi.session.digest"]) return jsgiResponse;

    sessionData = sessionData + "--" + digest;

    if (sessionData.length > 4096) {
        env["jsgi.errors"] += "Session Cookie data size exceeds 4k!  Content dropped";
        return jsgiResponse;
    }
    
    var options = env["jsgi.session.options"];

    var cookie = { value: sessionData };
    if (options["expires_after"])
        cookie.expires = new Date() + options["expires_after"];

    var response = new Response(jsgiResponse.status, jsgiResponse.headers, jsgiResponse.body);
    response.setCookie(key, cookie);

    return response;
}
Esempio n. 3
0
exports.handle = function(env) {
    var request = new Request(env);
    var response = new Response();

    var zazlenv = {};

    zazlenv["REQUEST_METHOD"] = env["REQUEST_METHOD"];
    zazlenv["URL_PATH"] = env["PATH_INFO"];
    zazlenv["PATH_INFO"] = env["PATH_INFO"];
    zazlenv["QUERY_STRING"] = env["QUERY_STRING"] || "";
    zazlenv["CONTENT_TYPE"] = env["CONTENT_TYPE"] || "";
    zazlenv["CONTENT_LENGTH"] = env["CONTENT_LENGTH"] || "";
    zazlenv["SERVER_NAME"] = env["SERVER_NAME"] || "";
    zazlenv["SERVER_PORT"] = env["SERVER_PORT"] || "";
    zazlenv["SERVER_PROTOCOL"] = env["SERVER_PROTOCOL"] || "";
    zazlenv["GATEWAY_INTERFACE"] = "CGI/1.1";
    zazlenv["SERVER_SOFTWARE"] = "Jack/Zazl/0.1";
    zazlenv["PATH_TRANSLATED"] = env["PATH_INFO"] || "";
    zazlenv["REMOTE_HOST"] = env["REMOTE_ADDR"] || "";
    zazlenv["REMOTE_ADDR"] = env["REMOTE_ADDR"] || "";
    zazlenv["REMOTE_USER"] = "******";
    zazlenv["AUTH_TYPE"] = "Unknown";
    zazlenv["jsengine"] = "commonjs";

    for (var i in env) {
        if (i.indexOf("HTTP_") == 0) {
        	zazlenv[i] = env[i];
        }
    }

    zazlenv["PARAMETERS"] = request.params();

    var responseJson = dtlapp(zazlenv);
    if (responseJson != null) {
        var responseData = eval("("+responseJson+")");
        response.status = responseData.status;
        for (var headerName in responseData.headers) {
        	response.setHeader(headerName, responseData.headers[headerName]);
        }
        response.write(responseData.renderedResponse);
        return response.finish();
    }
    else {
        var fileResponse = fileHandler(env);
        if (fileResponse.status == 404) {
            fileResponse = zazlFileHandler(env);
        }
        return fileResponse;
    }
}
Esempio n. 4
0
    return function(env) {
        
        CORE.flushTimeouts();
        
        // print(env["QUERY_STRING"])
        // print(decodeURIComponent(env["QUERY_STRING"]))
        
        var body = null;
        if (env["QUERY_STRING"])
            body = decodeURIComponent(env["QUERY_STRING"]);
        else if (env["REQUEST_METHOD"] === "POST")
            body = env["jsgi.input"].read().decodeToString("UTF-8");
        
        var requestObject = {};
        if (body)
            requestObject = JSON.parse(body);
            
        stream.print("\0purple(=>\0) request = "+JSON.stringify(requestObject));
        
        var responseObject = app(requestObject, env) || {};

        stream.print("\0purple(<=\0) response = "+JSON.stringify(responseObject));
        stream.print(Array(81).join("="));

        var response = Response.json(responseObject);

        return response;
    }
Esempio n. 5
0
exports.POST = function(env) {
    var params = new Request(env).POST(),
        msg = new Message(params);
        
    msg.put();
    
    return Response.redirect("/");
}
Esempio n. 6
0
File: async.js Progetto: cadorn/jack
map["/send"] = function(request) {
    var res = new Response(),
        message = new Request(request).params("message");
        
    var total = sessions.length;
    sessions = sessions.filter(function(session) {
        try {
            session.write("received: " + message + "<br />");
        } catch (e) {
            return false;
        }
        return true;
    });
    
    res.write("sent '" + message + "' to " + sessions.length + " clients, " + (total - sessions.length) + " closed.");
        
    return res.finish();
}
Esempio n. 7
0
File: async.js Progetto: cadorn/jack
map["/"] = function(request) {
    var res = new Response();
    
    res.write('<input type="text" id="m" value="hello">');
    res.write('<input type="button" value="Send" onclick="document.getElementById(\'r\').src=\'send?message=\'+encodeURIComponent(document.getElementById(\'m\').value);">');
    res.write('<iframe id="r"></iframe>');
    res.write('<a href="listen" target="_blank">listen</a>');
    res.write('<input value="listener" type="button" onclick="var f = document.createElement(\'iframe\'); f.src = \'listen\'; document.body.appendChild(f);">');
    
    return res.finish();
}