<commit_before>package org.scalatra

import scala.collection.SortedSet
import javax.servlet.http.{ HttpServletRequest, HttpServletRequestWrapper,
                            HttpServletResponse }

object MethodOverride {
  val ParamName = "_method"
  val HeaderName = SortedSet(
    "X-HTTP-METHOD-OVERRIDE", "X-HTTP-METHOD", "X-METHOD-OVERRIDE"
  )
}

/**
 * Mixin for clients that only support a limited set of HTTP verbs.
 * If the request is a POST and the `_method` request parameter is set,
 * the value of the `_method` parameter is treated as the request's method.
 */
trait MethodOverride extends Handler {

  abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
    val req2 = req.requestMethod match {
      case Post => new HttpServletRequestWrapper(req) {
        override def getMethod(): String =
          methodOverride(req) getOrElse req.getMethod
      }
      case _ => req
    }
    super.handle(req2, res)
  }

  private def methodOverride(req: HttpServletRequest) = {
    import MethodOverride._
    val methodOpt = req.parameters get ParamName
    methodOpt orElse {
      val headers = req.headers
      val headerKeyOpt = headers.keys.find { HeaderName contains _ }
      headerKeyOpt.flatMap { req.headers get _ }
    }<commit_msg>support case insensitive method override header checking, like backbone wants<commit_after>package org.scalatra

import scala.collection.SortedSet
import javax.servlet.http.{ HttpServletRequest, HttpServletRequestWrapper,
                            HttpServletResponse }

object MethodOverride {
  val ParamName = "_method"
  val HeaderName = SortedSet(
    "X-HTTP-METHOD-OVERRIDE", "X-HTTP-METHOD", "X-METHOD-OVERRIDE"
  )
}

/**
 * Mixin for clients that only support a limited set of HTTP verbs.
 * If the request is a POST and the `_method` request parameter is set,
 * the value of the `_method` parameter is treated as the request's method.
 */
trait MethodOverride extends Handler {

  abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
    val req2 = req.requestMethod match {
      case Post => new HttpServletRequestWrapper(req) {
        override def getMethod(): String =
          methodOverride(req) getOrElse req.getMethod
      }
      case _ => req
    }
    super.handle(req2, res)
  }

  private def methodOverride(req: HttpServletRequest) = {
    import MethodOverride._
    val methodOpt = req.parameters get ParamName
    methodOpt orElse {
      val headers = req.headers
      val headerKeyOpt = headers.keys.find { HeaderName contains _.toUpperCase() }
      headerKeyOpt.flatMap { req.headers get _ }
    }
{'fraction_non_alphanumeric': 0.07993966817496229, 'fraction_numerical': 0.0015082956259426848, 'mean_word_length': 3.2312599681020733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2647443', 'n_tokens_mistral': 743, 'n_tokens_neox': 725, 'n_words': 232}