<commit_before>package com.yammer.dropwizard.tasks

import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet}
import com.codahale.logula.Logging

class TaskServlet(tasks: Set[Task]) extends HttpServlet with Logging {
  private val tasksByName = tasks.groupBy { "/" + _.name }.mapValues { _.head }
  
  override def doPost(req: HttpServletRequest, resp: HttpServletResponse) {
    tasksByName.get(req.getPathInfo) match {
      case Some(task) => {
        try {
          val output = resp.getWriter
          task.execute(params(req), output)
          output.close()
        } catch {
          case e => {
            log.error(e, "Exception throwing while running %s", task)
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
          }
        }
      }
      case None => resp.sendError(HttpServletResponse.SC_NOT_FOUND)
    }
  }

  private def params(req: HttpServletRequest): Map[String, scala.Vector[String]] = {
    var params = Map.empty[String, Vector[String]]
    val names = req.getParameterNames
    while (names.hasMoreElements) {
      val name = names.nextElement().asInstanceOf[String]
      params += name -> (Vector.empty ++ req.getParameterValues(name))
    }
    params
  }
}
<commit_msg>Hard-code tasks to produce only text/plain output.<commit_after>package com.yammer.dropwizard.tasks

import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet}
import com.codahale.logula.Logging

class TaskServlet(tasks: Set[Task]) extends HttpServlet with Logging {
  private val tasksByName = tasks.groupBy { "/" + _.name }.mapValues { _.head }
  
  override def doPost(req: HttpServletRequest, resp: HttpServletResponse) {
    tasksByName.get(req.getPathInfo) match {
      case Some(task) => {
        try {
          resp.setContentType("text/plain")
          val output = resp.getWriter
          task.execute(params(req), output)
          output.close()
        } catch {
          case e => {
            log.error(e, "Exception throwing while running %s", task)
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
          }
        }
      }
      case None => resp.sendError(HttpServletResponse.SC_NOT_FOUND)
    }
  }

  private def params(req: HttpServletRequest): Map[String, scala.Vector[String]] = {
    var params = Map.empty[String, Vector[String]]
    val names = req.getParameterNames
    while (names.hasMoreElements) {
      val name = names.nextElement().asInstanceOf[String]
      params += name -> (Vector.empty ++ req.getParameterValues(name))
    }
    params
  }
}

{'fraction_non_alphanumeric': 0.10974201001155179, 'fraction_numerical': 0.0, 'mean_word_length': 2.966412213740458, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4891127', 'n_tokens_mistral': 755, 'n_tokens_neox': 762, 'n_words': 159}