<commit_before>library dart_fpm.fcgi.requests.response;

import 'package:dart_fpm/src/fcgi/fcgi.dart';
import 'dart:async';

typedef void DataFunction(Response, String);
typedef void DoneFunction(Response);

class Response {

  final int requestId;
  ProtocolStatus protocolStatus = ProtocolStatus.REQUEST_COMPLETE;
  int appStatus = 0;
  final List<String> _header = new List();
  bool _headerSent = false;
  final StreamController<String> _output = new StreamController();

  Response._(this.requestId);

  factory Response (int requestId, Function onData, Function onError,
      Function onDone) {
    Response response = new Response._(requestId);
    response._createListener(onData, onError, onDone);
    return response;
  }

  void _createListener(DataFunction onData, DataFunction onError,
      DoneFunction onDone) {
    _output.stream.listen((data) {
      if (!_headerSent) {
        onData(this, "${_header.join("\r\n")}\r\n\r\n");
        _headerSent;
      }
      onData(this, data);
    }, onError: (error) {
      onError(this, error);
    }, onDone: () {
      onDone(this);
    },
        cancelOnError: false);
  }

  StreamSink<String> get output  => _output;

  void close () {
    _output.close();
  }

  void header(dynamic entry) {
    _header.add(entry.toString());
  }

}<commit_msg>added endRequestRecord getter<commit_after>library dart_fpm.fcgi.requests.response;

import 'package:dart_fpm/src/fcgi/fcgi.dart';
import 'dart:async';

typedef void DataFunction(Response, String);

typedef void DoneFunction(Response);

class Response {

  final int requestId;
  ProtocolStatus protocolStatus = ProtocolStatus.REQUEST_COMPLETE;
  int appStatus = 0;
  final List<String> _header = new List();
  bool _headerSent = false;
  final StreamController<String> _output = new StreamController();

  Response._(this.requestId);

  factory Response (int requestId, Function onData, Function onError,
      Function onDone) {
    Response response = new Response._(requestId);
    response._createListener(onData, onError, onDone);
    return response;
  }

  void _createListener(DataFunction onData, DataFunction onError,
      DoneFunction onDone) {
    _output.stream.listen((data) {
      if (!_headerSent) {
        onData(this, "${_header.join("\r\n")}\r\n\r\n");
        _headerSent;
      }
      onData(this, data);
    }, onError: (error) {
      onError(this, error);
    }, onDone: () {
      onDone(this);
    },
        cancelOnError: false);
  }

  StreamSink<String> get output => _output;

  void close() {
    _output.close();
  }

  void header(dynamic entry) {
    _header.add(entry.toString());
  }

  FcgiRecord get endRequestRecord =>
      new FcgiRecord.generateResponse(
          requestId, new EndRequestBody(appStatus, protocolStatus));


}
{'fraction_non_alphanumeric': 0.11979913916786226, 'fraction_numerical': 0.0007173601147776184, 'mean_word_length': 3.5947281713344315, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '1062779', 'n_tokens_mistral': 890, 'n_tokens_neox': 858, 'n_words': 193}