omega.js
function intercept(req, res, next) {
    if (
         !route.test(req.url)           // Incorrect URL.
      || !req.headers.authorization     // Missing authorization.
      || options.method !== req.method  // Invalid method.
    ) return next();

    //
    // Handle unauthorized requests.
    //
    if (authorization !== req.headers.authorization) {
      res.statusCode = 401;
      res.setHeader('Content-Type', 'application/json');

      return res.end(JSON.stringify({
        ok: false,
        reason: [
          'I am programmed to protect, and sacrifice if necessary.',
          'Feel the power of my lazers! Pew pew!'
        ].join(' ')
      }));
    }

    var primus = this
      , buff = '';

    if (typeof options.middleware === 'function') {
      options.middleware(primus, parse, req, res, next);
    } else {
      //
      // Receive the data from the socket. The `setEncoding` ensures that Unicode
      // chars are correctly buffered and parsed before the `data` event is
      // emitted.
      //
      req.setEncoding('utf8');
      req.on('data', function data(chunk) {
        buff += chunk;
      }).once('end', function end() {
        parse(primus, buff, res);
      });
    }
  }
function intercept(req, res, next) {
    if (
         !route.test(req.url)           // Incorrect URL.
      || !req.headers.authorization     // Missing authorization.
      || options.method !== req.method  // Invalid method.
    ) return next();

    //
    // Handle unauthorized requests.
    //
    if (authorization !== req.headers.authorization) {
      res.statusCode = 401;
      res.setHeader('Content-Type', 'application/json');

      return res.end(JSON.stringify({
        ok: false,
        reason: [
          'I am programmed to protect, and sacrifice if necessary.',
          'Feel the power of my lazers! Pew pew!'
        ].join(' ')
      }));
    }

    var primus = this
      , buff = '';

    if (typeof options.middleware === 'function') {
      options.middleware(primus, parse, req, res, next);
    } else {
      //
      // Receive the data from the socket. The `setEncoding` ensures that Unicode
      // chars are correctly buffered and parsed before the `data` event is
      // emitted.
      //
      req.setEncoding('utf8');
      req.on('data', function data(chunk) {
        buff += chunk;
      }).once('end', function end() {
        parse(primus, buff, res);
      });
    }
  }
function intercept ( req , res , next ) { if ( ! route . test ( req . url ) // Incorrect URL. || ! req . headers . authorization // Missing authorization. || options . method !== req . method // Invalid method. ) return next ( ) ; // // Handle unauthorized requests. // if ( authorization !== req . headers . authorization ) { res . statusCode = 401 ; res . setHeader ( 'Content-Type' , 'application/json' ) ; return res . end ( JSON . stringify ( { ok : false , reason : [ 'I am programmed to protect, and sacrifice if necessary.' , 'Feel the power of my lazers! Pew pew!' ] . join ( ' ' ) } ) ) ; } var primus = this , buff = '' ; if ( typeof options . middleware === 'function' ) { options . middleware ( primus , parse , req , res , next ) ; } else { // // Receive the data from the socket. The `setEncoding` ensures that Unicode // chars are correctly buffered and parsed before the `data` event is // emitted. // req . setEncoding ( 'utf8' ) ; req . on ( 'data' , function data ( chunk ) { buff += chunk ; } ) . once ( 'end' , function end ( ) { parse ( primus , buff , res ) ; } ) ; } }
The actual middleware layer.

@param {Request} req Incoming HTTP request.
@param {Response} res Outgoing HTTP response.
@param {Function} next Middleware continuation.
@api private
The actual middleware layer .