<commit_before>'use strict';

var http = require('http');
var util = require('util');
var PassThrough = require('stream').PassThrough;

// A PassThrough stream that takes a list of valid status codes. The
// supplied status codes will act as a whilelist of allowed HTTP
// response codes. If a HTTP reponse is received which doens't conform
// to the whilelist, an error event is emitted.
var Status = function () {
  var self = this;
  PassThrough.call(this);

  if (arguments.length > 0)
    var codes = Array.prototype.slice.call(arguments);

  // Listen for the special `response` event emitted by the flowHttp
  // module
  this.once('response', function (res) {
    // Forward the `response` event down the pipe-line
    self._forwardFlowHttpResponse(res);
    var code = res.statusCode;
    if (codes && codes.indexOf(code) === -1) {
      var err = new Error('Unexpected response: ' + code + ' ' + http.STATUS_CODES[code]);
      err.method = self._src.req.method;
      err.url = self._src.req.url;
      self.emit('error', err);
    }
  });

  // Record the source of the pipe to be used above
  this.once('pipe', function (src) {
    self._src = src;
  });
};

util.inherits(Status, PassThrough);

module.exports = Status;
<commit_msg>Bug fix: Add request path to invalid status code errors<commit_after>'use strict';

var http = require('http');
var util = require('util');
var PassThrough = require('stream').PassThrough;

// A PassThrough stream that takes a list of valid status codes. The
// supplied status codes will act as a whilelist of allowed HTTP
// response codes. If a HTTP reponse is received which doens't conform
// to the whilelist, an error event is emitted.
var Status = function () {
  var self = this;
  PassThrough.call(this);

  if (arguments.length > 0)
    var codes = Array.prototype.slice.call(arguments);

  // Listen for the special `response` event emitted by the flowHttp
  // module
  this.once('response', function (res) {
    // Forward the `response` event down the pipe-line
    self._forwardFlowHttpResponse(res);
    var code = res.statusCode;
    if (codes && codes.indexOf(code) === -1) {
      var err = new Error('Unexpected response: ' + code + ' ' + http.STATUS_CODES[code]);
      err.method = self._src.req.method;
      err.path = self._src.req.path;
      self.emit('error', err);
    }
  });

  // Record the source of the pipe to be used above
  this.once('pipe', function (src) {
    self._src = src;
  });
};

util.inherits(Status, PassThrough);

module.exports = Status;

{'fraction_non_alphanumeric': 0.1273659305993691, 'fraction_numerical': 0.0015772870662460567, 'mean_word_length': 3.314625850340136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5943656', 'n_tokens_mistral': 768, 'n_tokens_neox': 742, 'n_words': 263}