<commit_before>package play.core.server.netty

import org.jboss.netty.channel._
import org.jboss.netty.handler.codec.http._


import play.api.mvc._
import play.api.libs.iteratee._
import play.api.libs.iteratee.Input._

import scala.collection.JavaConverters._
import collection.immutable.TreeMap
import play.core.utils.CaseInsensitiveOrdered

private[netty] trait Helpers {

  def socketOut[A](ctx: ChannelHandlerContext)(frameFormatter: play.api.mvc.WebSocket.FrameFormatter[A]): Iteratee[A, Unit] = {
    val channel = ctx.getChannel()
    val nettyFrameFormatter = frameFormatter.asInstanceOf[play.core.server.websocket.FrameFormatter[A]]

    def step(future: Option[ChannelFuture])(input: Input[A]): Iteratee[A, Unit] =
      input match {
        case El(e) => Cont(step(Some(channel.write(nettyFrameFormatter.toFrame(e)))))
        case e @ EOF => future.map(_.addListener(ChannelFutureListener.CLOSE)).getOrElse(channel.close()); Done((), e)
        case Empty => Cont(step(future))
      }

    Enumeratee.breakE[A](_ => !channel.isConnected()).transform(Cont(step(None)))
  }

  def getHeaders(nettyRequest: HttpRequest): Headers = {

    //note: the underlying netty map is case insensitive on the key & very efficient
    //todo: it would be nice to get to that same level of efficiency, either by wrapping
    //      or with something more efficient than TreeMap (does that matter?)
    val headers: Map[String, Seq[String]] = {
      val pairs = nettyRequest.getHeaderNames.asScala.map { key =>
        key -> nettyRequest.getHeaders(key).asScala
      }
      TreeMap(pairs.toSeq: _*)(CaseInsensitiveOrdered)
    }

    new Headers {
      def getAll(key: String) = headers.get(key).flatten.toSeq
      def keys = headers.keySet<commit_msg>fix comment ( I no longer believe unerlying netty structure is case insensitive)<commit_after>package play.core.server.netty

import org.jboss.netty.channel._
import org.jboss.netty.handler.codec.http._


import play.api.mvc._
import play.api.libs.iteratee._
import play.api.libs.iteratee.Input._

import scala.collection.JavaConverters._
import collection.immutable.TreeMap
import play.core.utils.CaseInsensitiveOrdered

private[netty] trait Helpers {

  def socketOut[A](ctx: ChannelHandlerContext)(frameFormatter: play.api.mvc.WebSocket.FrameFormatter[A]): Iteratee[A, Unit] = {
    val channel = ctx.getChannel()
    val nettyFrameFormatter = frameFormatter.asInstanceOf[play.core.server.websocket.FrameFormatter[A]]

    def step(future: Option[ChannelFuture])(input: Input[A]): Iteratee[A, Unit] =
      input match {
        case El(e) => Cont(step(Some(channel.write(nettyFrameFormatter.toFrame(e)))))
        case e @ EOF => future.map(_.addListener(ChannelFutureListener.CLOSE)).getOrElse(channel.close()); Done((), e)
        case Empty => Cont(step(future))
      }

    Enumeratee.breakE[A](_ => !channel.isConnected()).transform(Cont(step(None)))
  }

  def getHeaders(nettyRequest: HttpRequest): Headers = {

    //todo: wrap the underlying map in a structure more efficient than TreeMap
    val headers: Map[String, Seq[String]] = {
      val pairs = nettyRequest.getHeaderNames.asScala.map { key =>
        key -> nettyRequest.getHeaders(key).asScala
      }
      TreeMap(pairs.toSeq: _*)(CaseInsensitiveOrdered)
    }

    new Headers {
      def getAll(key: String) = headers.get(key).flatten.toSeq
      def keys = headers.keySet
{'fraction_non_alphanumeric': 0.12331180270111568, 'fraction_numerical': 0.0, 'mean_word_length': 4.062407132243685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6615860', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1059, 'n_words': 221}