How to use the http-parser-js.HTTPParser.REQUEST function in http-parser-js

To help you get started, we’ve selected a few http-parser-js 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 jscissr / http-node / _http_server.js View on Github external
// otherwise, destroy on timeout by default
  if (self.timeout)
    socket.setTimeout(self.timeout);
  socket.on('timeout', function() {
    var req = socket.parser && socket.parser.incoming;
    var reqTimeout = req && !req.complete && req.emit('timeout', socket);
    var res = socket._httpMessage;
    var resTimeout = res && res.emit('timeout', socket);
    var serverTimeout = self.emit('timeout', socket);

    if (!reqTimeout && !resTimeout && !serverTimeout)
      socket.destroy();
  });

  var parser = parsers.alloc();
  parser.reinitialize(HTTPParser.REQUEST);
  parser.socket = socket;
  socket.parser = parser;
  parser.incoming = null;

  // Propagate headers limit from server instance to parser
  if (typeof this.maxHeadersCount === 'number') {
    parser.maxHeaderPairs = this.maxHeadersCount << 1;
  } else {
    // Set default value because parser may be reused from FreeList
    parser.maxHeaderPairs = 2000;
  }

  socket.addListener('error', socketOnError);
  socket.addListener('close', serverSocketCloseListener);
  parser.onIncoming = parserOnIncoming;
  socket.on('end', socketOnEnd);
github JarvusInnovations / node-request-to-curl / index.js View on Github external
function parseRequestBody(request) {
    var parser = new HTTPParser(HTTPParser.REQUEST);

    parser.body = '';
    parser.bodyStart = 0;

    parser[HTTPParser.kOnBody | 0] = function (b, start) {
        if (!parser.bodyStart) {
            parser.bodyStart = start;
        }

        parser.body = b;
    };

    if (typeof request === 'string') {
        request = Buffer.from(request);
    }
github sx1989827 / DOClever / Desktop / node_modules / websocket-driver / lib / websocket / http_parser.js View on Github external
'use strict';

var NodeHTTPParser = require('http-parser-js').HTTPParser;

var VERSION = process.version.match(/[0-9]+/g).map(function(n) { return parseInt(n, 10) });

var TYPES = {
  request:  NodeHTTPParser.REQUEST  || 'request',
  response: NodeHTTPParser.RESPONSE || 'response'
};

var HttpParser = function(type) {
  this._type     = type;
  this._parser   = new NodeHTTPParser(TYPES[type]);
  this._complete = false;
  this.headers   = {};

  var current = null,
      self    = this;

  this._parser.onHeaderField = function(b, start, length) {
    current = b.toString('utf8', start, start + length).toLowerCase();
  };
github publiclab / Leaflet.DistortableImage / node_modules / websocket-driver / lib / websocket / http_parser.js View on Github external
'use strict';

var NodeHTTPParser = require('http-parser-js').HTTPParser,
    Buffer         = require('safe-buffer').Buffer;

var TYPES = {
  request:  NodeHTTPParser.REQUEST  || 'request',
  response: NodeHTTPParser.RESPONSE || 'response'
};

var HttpParser = function(type) {
  this._type     = type;
  this._parser   = new NodeHTTPParser(TYPES[type]);
  this._complete = false;
  this.headers   = {};

  var current = null,
      self    = this;

  this._parser.onHeaderField = function(b, start, length) {
    current = b.toString('utf8', start, start + length).toLowerCase();
  };
github makuga01 / dnsFookup / FE / node_modules / websocket-driver / lib / websocket / http_parser.js View on Github external
'use strict';

var NodeHTTPParser = require('http-parser-js').HTTPParser,
    Buffer         = require('safe-buffer').Buffer;

var TYPES = {
  request:  NodeHTTPParser.REQUEST  || 'request',
  response: NodeHTTPParser.RESPONSE || 'response'
};

var HttpParser = function(type) {
  this._type     = type;
  this._parser   = new NodeHTTPParser(TYPES[type]);
  this._complete = false;
  this.headers   = {};

  var current = null,
      self    = this;

  this._parser.onHeaderField = function(b, start, length) {
    current = b.toString('utf8', start, start + length).toLowerCase();
  };