onData method

  1. @override
void onData(
  1. dynamic data
)
override

Handles incoming data. Due to a bug in \n handling by browsers, we expect a escaped string.

Implementation

@override
void onData(data) {
  // we leverage the qs module so that we get built-in DoS protection
  // and the fast alternative to decodeURIComponent
  data = parse(data)['d'];
  if (data is String) {
    // client will send already escaped newlines as \\\\n and newlines as \\n
    // \\n must be replaced with \n and \\\\n with \\n
    data = data.replaceAllMapped(RegExp(r'(\\)?\\n'), (match) {
      throw UnimplementedError('Not implemented yet');
    });
    super.onData(data.replaceAll(RegExp(r'\\\\n'), '\\n'));
  }
}