<commit_before>package org.apache.mesos.chronos.scheduler.api

import java.io.{InputStream, OutputStream}
import java.net.{HttpURLConnection, URL}
import java.util.logging.{Level, Logger}
import javax.servlet._
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

import org.apache.mesos.chronos.scheduler.jobs.JobScheduler
import com.google.inject.Inject

import scala.collection.JavaConverters._
import scala.language.postfixOps

/**
 * Simple filter that redirects to the leader if applicable.
 * @author <NAME> (<EMAIL>)
 */
class RedirectFilter @Inject()(val jobScheduler: JobScheduler) extends Filter {
  val log = Logger.getLogger(getClass.getName)

  def init(filterConfig: FilterConfig) {}

  def doFilter(rawRequest: ServletRequest,
               rawResponse: ServletResponse,
               chain: FilterChain) {
    rawRequest match {
      case request: HttpServletRequest =>
        val leaderData = jobScheduler.getLeader
        val response = rawResponse.asInstanceOf[HttpServletResponse]

        if (jobScheduler.isLeader) {
          chain.doFilter(request, response)
        } else {<commit_msg>don't allow proxying requests to self (#497)<commit_after>package org.apache.mesos.chronos.scheduler.api

import java.io.{InputStream, OutputStream}
import java.net.{HttpURLConnection, URL}
import java.util.logging.{Level, Logger}
import javax.servlet._
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

import org.apache.mesos.chronos.scheduler.jobs.JobScheduler
import com.google.inject.Inject

import scala.collection.JavaConverters._
import scala.language.postfixOps
import mesosphere.chaos.http.HttpConf
import org.apache.mesos.chronos.scheduler.config.SchedulerConfiguration

/**
 * Simple filter that redirects to the leader if applicable.
 * @author <NAME> (<EMAIL>)
 */
class RedirectFilter @Inject()(val jobScheduler: JobScheduler, val config: SchedulerConfiguration with HttpConf) extends Filter {
  val log = Logger.getLogger(getClass.getName)

  def init(filterConfig: FilterConfig) {}

  def doFilter(rawRequest: ServletRequest,
               rawResponse: ServletResponse,
               chain: FilterChain) {
    rawRequest match {
      case request: HttpServletRequest =>
        val leaderData = jobScheduler.getLeader
        val response = rawResponse.asInstanceOf[HttpServletResponse]
        val currentId = "%s:%d".format(config.hostname(), config.httpPort())

        if (jobScheduler.isLeader || currentId == leaderData) {
          chain.doFilter(request, response)
        } else {
{'fraction_non_alphanumeric': 0.09644670050761421, 'fraction_numerical': 0.0011714174150722373, 'mean_word_length': 4.196754563894523, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2895047', 'n_tokens_mistral': 727, 'n_tokens_neox': 720, 'n_words': 165}