<commit_before>package com.ponkotuy.proxy

import com.github.theon.uri.Uri
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.finagle.{http, Service, Http}
import com.twitter.util.{Future, Await}
import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponse, HttpRequest}
import com.ponkotuy.intercept.{Intercepter, PassThrough}

/** Proxy by Finagle
  *
  * @param hosts: Hosts. Require Port Number(hostname:80 etc...)
  * @param port: Server Port.
  * @param inter: com.ponkotuy.intercept.Intercepter
  */
class FinagleProxy(hosts: String, port: Int, inter: Intercepter = new PassThrough) {
  val client = ClientBuilder()
    .codec(http.Http())
    .hosts(hosts)
    .hostConnectionLimit(4).build()

  val service = new Service[HttpRequest, HttpResponse] {
    def apply(req: HttpRequest): Future[HttpResponse] = {
      val res = if(req.getMethod == HttpMethod.POST) {
        val uri = Uri.parseUri(req.getUri)
        req.setUri(uri.pathRaw)
        client.apply(req)
      } else {
        client.apply(req)
      }
      res.foreach(rs => inter.input(req, rs))<commit_msg>Fix Over Http Content Length<commit_after>package com.ponkotuy.proxy

import com.github.theon.uri.Uri
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.finagle.{http, Service, Http}
import com.twitter.util.{Future, Await}
import org.jboss.netty.handler.codec.http.{HttpMethod, HttpResponse, HttpRequest}
import com.ponkotuy.intercept.{Intercepter, PassThrough}
import com.twitter.conversions.storage._

/** Proxy by Finagle
  *
  * @param hosts: Hosts. Require Port Number(hostname:80 etc...)
  * @param port: Server Port.
  * @param inter: com.ponkotuy.intercept.Intercepter
  */
class FinagleProxy(hosts: String, port: Int, inter: Intercepter = new PassThrough) {
  val client = ClientBuilder()
    .codec(http.Http().maxRequestSize(128.megabytes))
    .codec(http.Http().maxResponseSize(128.megabytes))
    .hosts(hosts)
    .hostConnectionLimit(4).build()

  val service = new Service[HttpRequest, HttpResponse] {
    def apply(req: HttpRequest): Future[HttpResponse] = {
      val res = if(req.getMethod == HttpMethod.POST) {
        val uri = Uri.parseUri(req.getUri)
        req.setUri(uri.pathRaw)
        client.apply(req)
      } else {
        client.apply(req)
      }
      res.foreach(rs => inter.input(req, rs))
{'fraction_non_alphanumeric': 0.12952705581593524, 'fraction_numerical': 0.0051129100979974435, 'mean_word_length': 3.7918367346938777, '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': '2273664', 'n_tokens_mistral': 789, 'n_tokens_neox': 764, 'n_words': 156}