<commit_before>Library streamy.proxy;

import 'dart:async';
import 'dart:html';
import 'dart:json' as json;
import 'base.dart';

/// A [RequestHandler] that proxies through a frontend server.
class ProxyClient extends RequestHandler {

  /// The base url of the proxy.
  final String proxyUrl;
  final StreamyHttpService httpHandler;

  ProxyClient(this.proxyUrl, {this.httpHandler: const DartHtmlHttpService()});

  Stream handle(Request req) {
    var url = '$proxyUrl/${req.root.servicePath}${req.path}';
    var payload = req.hasPayload ? json.stringify(req.payload) : null;
    return httpHandler.request(url, req.httpMethod, payload: payload).then((resp) {
      if (resp.statusCode != 200) {
        throw new ProxyException(resp.statusCode,
            'API call returned status: ${resp.statusText}');
      }
      return req.responseDeserializer(resp.body);
    }).asStream();
  }
}

class ProxyException implements Exception {

  final String message;
  final int code;

  ProxyException(this.message, this.code);

  String toString() => '$code: $message';
}

class StreamyHttpResponse {
  final int statusCode;
  final String statusText;
  final String body;

  StreamyHttpResponse(this.statusCode, this.statusText, this.body);
}

abstract class StreamyHttpService {

  Future<StreamyHttpResponse> request(String url, String method, {String payload: null, String contentType: 'application/json'});
}

class DartHtmlHttpService implements StreamyHttpService {

  const DartHtmlHttpService();

  Future<StreamyHttpResponse> request(String url, String method, {String payload: null, String contentType: 'application/json'}) {
    var c = new Completer<StreamyHttpResponse>();

    var req = new HttpRequest();
    req.open(method, url, async: true);
    if (payload != null) {
      req.setRequestHeader('Content-Type': contentType);
      req.send(payload);
    } else {
      req.send();
    }

    req.onLoad.first.then((_) {
      c.complete(new StreamyHttpResponse(req.status, req.statusText, req.responseText));
    };

    req.onError.first.then(c.completeError);

    if (payload != null) {
      res = HttpRequest.request(url, method: method, sendData: payload, requestHeaders: {'Content-Type': contentType});
    } else {
      res = HttpRequest.request(url, method: method);
    }
    return c.future;
  }
}
<commit_msg>Remove missed section of code.<commit_after>Library streamy.proxy;

import 'dart:async';
import 'dart:html';
import 'dart:json' as json;
import 'base.dart';

/// A [RequestHandler] that proxies through a frontend server.
class ProxyClient extends RequestHandler {

  /// The base url of the proxy.
  final String proxyUrl;
  final StreamyHttpService httpHandler;

  ProxyClient(this.proxyUrl, {this.httpHandler: const DartHtmlHttpService()});

  Stream handle(Request req) {
    var url = '$proxyUrl/${req.root.servicePath}${req.path}';
    var payload = req.hasPayload ? json.stringify(req.payload) : null;
    return httpHandler.request(url, req.httpMethod, payload: payload).then((resp) {
      if (resp.statusCode != 200) {
        throw new ProxyException(resp.statusCode,
            'API call returned status: ${resp.statusText}');
      }
      return req.responseDeserializer(resp.body);
    }).asStream();
  }
}

class ProxyException implements Exception {

  final String message;
  final int code;

  ProxyException(this.message, this.code);

  String toString() => '$code: $message';
}

class StreamyHttpResponse {
  final int statusCode;
  final String statusText;
  final String body;

  StreamyHttpResponse(this.statusCode, this.statusText, this.body);
}

abstract class StreamyHttpService {

  Future<StreamyHttpResponse> request(String url, String method, {String payload: null, String contentType: 'application/json'});
}

class DartHtmlHttpService implements StreamyHttpService {

  const DartHtmlHttpService();

  Future<StreamyHttpResponse> request(String url, String method, {String payload: null, String contentType: 'application/json'}) {
    var c = new Completer<StreamyHttpResponse>();

    var req = new HttpRequest();
    req.open(method, url, async: true);
    if (payload != null) {
      req.setRequestHeader('Content-Type': contentType);
      req.send(payload);
    } else {
      req.send();
    }

    req.onLoad.first.then((_) {
      c.complete(new StreamyHttpResponse(req.status, req.statusText, req.responseText));
    };
    req.onError.first.then(c.completeError);

    return c.future;
  }
}

{'fraction_non_alphanumeric': 0.12220732797140303, 'fraction_numerical': 0.0013404825737265416, 'mean_word_length': 4.007829977628635, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4067429', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1317, 'n_words': 339}