How to use the juice.Utils function in juice

To help you get started, we’ve selected a few juice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashb / juice / lib / juice / engine / cgi.js View on Github external
CGI.sendResponse = function sendResponse(res) {
  if (typeof res != "object") {
    CGI.sendResponse(CGI.handleError("response is not an object"));
    return;
  }

  var { status: code, headers: headers, body: body } = res;

  if (code && parseInt(code) != code || code < 100) {
    CGI.sendResponse(CGI.handleError("invalid code"));
    return;
  }

  var hdrs = new juice.Utils.Headers(Iterator(headers));

  if (typeof body == "function") {
    //system.stderr.print("body is a function, calling");
    body = body();
  }

  var h_string = hdrs.toString();

  if (h_string.length)
    h_string += "\r\n"

  system.stdout.write("Status: " + code + "\r\n" +
                      h_string + "\r\n");

  // Work out what kind of body we have.