How to use the http-parser-js.HTTPParser.RESPONSE 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 evanshortiss / express-expeditious / lib / parse-http-response.js View on Github external
module.exports = function getHttpResponseData (httpContentBuffer) {
  const parser = new HTTPParser(HTTPParser.RESPONSE);
  let httpData = {};

  parser[HTTPParser.kOnMessageComplete] = noop;
  parser[HTTPParser.kOnHeaders] = noop;

  // Get headers and parse them to an object format for easier use
  parser[HTTPParser.kOnHeadersComplete] = function (meta) {
    const headerObject = {};

    for (let i = 0; i < meta.headers.length; i += 2) {
      headerObject[meta.headers[i]] = meta.headers[i + 1];
    }

    httpData = xtend(httpData, meta, {
      headers: headerObject
    });
github mcollina / autocannon / lib / httpClient.js View on Github external
this.opts = clone(opts)

  this.opts.setupClient = this.opts.setupClient || noop
  this.opts.pipelining = this.opts.pipelining || 1
  this.opts.port = this.opts.port || 80
  this.timeout = (this.opts.timeout || 10) * 1000
  this.ipc = !!this.opts.socketPath
  this.secure = this.opts.protocol === 'https:'
  this.auth = this.opts.auth || null

  if (this.secure && this.opts.port === 80) {
    this.opts.port = 443
  }

  this.parser = new HTTPParser(HTTPParser.RESPONSE)
  this.requestIterator = new RequestIterator(this.opts)

  this.reqsMade = 0

  // used for request limiting
  this.responseMax = this.opts.responseMax

  // used for rate limiting
  this.reqsMadeThisSecond = 0
  this.rate = this.opts.rate

  // used for forcing reconnects
  this.reconnectRate = this.opts.reconnectRate

  this.resData = new Array(this.opts.pipelining)
  for (let i = 0; i < this.opts.pipelining; i++) {
github mcollina / undici / lib / client.js View on Github external
constructor (url, opts = {}) {
    super()

    if (!(url instanceof URL)) {
      url = new URL(url)
    }

    this.url = url

    // state machine, might need more states
    this.closed = false

    this.parser = new HTTPParser(HTTPParser.RESPONSE)

    this[kTLSOpts] = opts.tls || opts.https

    const endRequest = () => {
      this.socket.write('\r\n', 'ascii')
      this.socket.uncork()
      this._needHeaders++
      this[kRead]()
    }

    this.timeout = opts.timeout || 30000 // 30 seconds
    this[kCallbacks] = []
    this[kRequests] = []

    const timerCb = () => {
      if (this[kCallbacks].length > 0) {
github jscissr / http-node / _http_client.js View on Github external
function tickOnSocket(req, socket) {
  var parser = parsers.alloc();
  req.socket = socket;
  req.connection = socket;
  parser.reinitialize(HTTPParser.RESPONSE);
  parser.socket = socket;
  parser.incoming = null;
  parser.outgoing = req;
  req.parser = parser;

  socket.parser = parser;
  socket._httpMessage = req;

  // Setup "drain" propagation.
  httpSocketSetup(socket);

  // Propagate headers limit from request object to parser
  if (typeof req.maxHeadersCount === 'number') {
    parser.maxHeaderPairs = req.maxHeadersCount << 1;
  } else {
    // Set default value because parser may be reused from FreeList
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();
  };

  this._parser.onHeaderValue = function(b, start, length) {
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();
  };

  this._parser.onHeaderValue = function(b, start, length) {
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();
  };

  this._parser.onHeaderValue = function(b, start, length) {