RingoJS

Module ringo/jsgi/connector

Low-level JSGI adapter implementation.

Functions


AsyncResponse (request, timeout)

Creates a streaming asynchronous response. The returned response object can be used both synchronously from the current thread or asynchronously from another thread, even after the original thread has finished execution. AsyncResponse objects are threadsafe.

To enable async support inside a Servlet 3.0+ container, an additional <async-supported>true</async-supported> element in the web.xml deployment descriptor might be required. This indicates that Ringo's JsgiServlet supports asynchronous request processing.

Example

const response = new AsyncResponse(request, 10000);
response.start(200, {"Content-Type": "text/plain"});

// this functions returns a ringo promise
doSomeAsyncStuff().then(function(data) {
  // write out result
  response.write(data);
  response.close();
}, function() {
  // just close the connection in case of an error
  response.close();
});

return response;

Parameters

Object request

the JSGI request object

Number timeout

time in milliseconds in which the async operation has to be completed; otherwise the request is aborted by the Servlet container. A negative value lets the async operation never time out. Defaults to 30 seconds.

Returns

Object

AsyncResponse object with helpers to control the response's WriteListener. Contains the following methods:

start(status, headers)
sends the status code and HTTP headers object, must be called before any write
write(data, encoding)
adds the given data (instance of String or Binary) to output queue to be written back to the client
flush()
forces any queued data to be written out
close()
completes the async response and closes the write listener


handleRequest (moduleId, functionObj, request)

Handle a JSGI request.

Parameters

String moduleId

the module id. Ignored if functionObj is already a function.

Function|String functionObj

the function, either as function object or function name to be imported from the module moduleId.

Object request

the JSGI request object

Returns

Object

the JSGI response object