<commit_before>package com.github.ornicar.scalariver

import scala.util.{ Try, Success, Failure }
import tiscaf._

object ScalariverServer extends HServer with App {

  def port = args.toIndexedSeq lift 0 flatMap { p =>
    Try(p.toInt).toOption
  } getOrElse 8098

  val apps = Seq(ScalariformApp, StaticApp)
  val ports = Set(port)
  override protected val name = "scalariver"
  override protected val maxPostDataLength = 1024 * 8
  // do not start the stop thread
  override protected def startStopListener {}

  start
  println("press enter to stop...")
  Console.readLine
  stop
}

/** The application that serves the pages */
object ScalariformApp extends HApp {

  override def keepAlive = false
  override def gzip = false
  override def tracking = HTracking.NotAllowed

  def resolve(req: HReqData): Option[HLet] =
    if (req.method == HReqType.PostData) Some(ScalariformLet) else None
}

/** Serves the current server time */
object ScalariformLet extends HSimpleLet {

  def act(talk: HTalk) {
    Format(talk.req) match {
      case Success(x) ⇒ talk
        .setContentType("text/plain")
        .setContentLength(x.length)
        .setStatus(HStatus.OK)
        .write(x)
      case Failure(e) ⇒ talk
        .setStatus(HStatus.BadRequest)
        .setContentLength(e.getMessage.length)
        .write(e.getMessage)
    }
  }<commit_msg>fix http response content encoding<commit_after>package com.github.ornicar.scalariver

import scala.util.{ Try, Success, Failure }
import tiscaf._

object ScalariverServer extends HServer with App {

  def port = args.toIndexedSeq lift 0 flatMap { p =>
    Try(p.toInt).toOption
  } getOrElse 8098

  val apps = Seq(ScalariformApp, StaticApp)
  val ports = Set(port)
  override protected val name = "scalariver"
  override protected val maxPostDataLength = 1024 * 8
  // do not start the stop thread
  override protected def startStopListener {}

  start
  println("press enter to stop...")
  Console.readLine
  stop
}

/** The application that serves the pages */
object ScalariformApp extends HApp {

  override def keepAlive = false
  override def gzip = false
  override def chunked = false
  override def tracking = HTracking.NotAllowed

  def resolve(req: HReqData): Option[HLet] =
    if (req.method == HReqType.PostData) Some(ScalariformLet) else None
}

/** Serves the current server time */
object ScalariformLet extends HSimpleLet {

  def act(talk: HTalk) {
    Format(talk.req) match {
      case Success(x) ⇒ {
        val bytes = x getBytes "UTF-8"
        talk
        .setContentType("text/plain; charset=UTF-8")
        .setCharacterEncoding("UTF-8")
        .setContentLength(bytes.size)
        .setStatus(HStatus.OK)
        .write(bytes)
      }
      case Failure(e) ⇒ talk
        .setStatus(HStatus.BadRequest)
        .setContentLength(e.getMessage.length)
        .write(e.getMessage)
    }
  }
{'fraction_non_alphanumeric': 0.09397841977027498, 'fraction_numerical': 0.008005569091541943, 'mean_word_length': 3.1652173913043478, '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': '4489438', 'n_tokens_mistral': 920, 'n_tokens_neox': 885, 'n_words': 257}