<commit_before>function Entry() {
  this.data = {
    status:  0,
    headers: {},
    body:    []
  };
};
Entry.prototype = {
  isCachable: function() {
    return this.data.status == 200;
  },

  write: function(chunk, encoding) {
    this.data.body.push({
      data:     chunk,
      encoding: encoding
    });
  },

  finalize: function(response) {
    this.data.status = response.statusCode;
    this.data.headers = response.headers;
  },

  hook: function(response, onEndCallback) {
    var entry = this;

    var originalWrite = response.write;
    response.write = function(chunk, encoding) {
      entry.write(chunk, encoding);
      return originalWrite.call(response, chunk, encoding);
    };

    var originalEnd = response.end;
    response.end = function(chunk, encoding) {
      entry.write(chunk, encoding);
      var returnValue = originalEnd.call(response, chunk, encoding);

      entry.finalize(response);
      entry.tryStore(onEndCallback);

      return returnValue;
    };
  },

  tryStore: function(callback) {
    if (this.isCachable())
      callback(this.data);<commit_msg>Store headers correctly.<commit_after>function Entry() {
  this.data = {
    status:  0,
    headers: {},
    body:    []
  };
};
Entry.prototype = {
  isCachable: function() {
    return this.data.status == 200;
  },

  write: function(chunk, encoding) {
    this.data.body.push({
      data:     chunk,
      encoding: encoding
    });
  },

  finalize: function(response) {
    this.data.status = response.statusCode;
    this.data.headers = response.headers || response._headers; // currently there is no public method to get all headers... why?
  },

  hook: function(response, onEndCallback) {
    var entry = this;

    var originalWrite = response.write;
    response.write = function(chunk, encoding) {
      entry.write(chunk, encoding);
      return originalWrite.call(response, chunk, encoding);
    };

    var originalEnd = response.end;
    response.end = function(chunk, encoding) {
      entry.write(chunk, encoding);
      var returnValue = originalEnd.call(response, chunk, encoding);

      entry.finalize(response);
      entry.tryStore(onEndCallback);

      return returnValue;
    };
  },

  tryStore: function(callback) {
    if (this.isCachable())
      callback(this.data);
{'fraction_non_alphanumeric': 0.13119026933101652, 'fraction_numerical': 0.0034752389226759338, 'mean_word_length': 2.877104377104377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2459535', 'n_tokens_mistral': 703, 'n_tokens_neox': 680, 'n_words': 147}