<commit_before>package unfiltered.netty.websockets

import unfiltered.request._
import unfiltered.response._
import unfiltered.netty._

import org.jboss.{netty => jnetty}
import jnetty.handler.codec.http.HttpHeaders
import jnetty.channel.{Channel, ChannelHandlerContext, MessageEvent, SimpleChannelUpstreamHandler}
import jnetty.buffer.ChannelBuffer

object Plan {
  type SocketIntent = PartialFunction[SocketCallback, Unit]
  type Intent = PartialFunction[RequestBinding, SocketIntent]
  type Pass = (ChannelHandlerContext, MessageEvent) => Unit
}

private [websockets] object ProtocolRequestHeader extends StringHeader(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL)
private [websockets] object SecKeyOne extends StringHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY1)
private [websockets] object SecKeyTwo extends StringHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY2)
private [websockets] object OriginRequestHeader extends StringHeader(HttpHeaders.Names.ORIGIN)
private [websockets] object ConnectionUpgrade {
  def unapply[T](req: HttpRequest[T]) =
    unfiltered.request.Connection(req).filter {
      _.equalsIgnoreCase(HttpHeaders.Values.UPGRADE)
    }
}

private [websockets] object UpgradeWebsockets {
  def unapply[T](req: HttpRequest[T]) =
    Upgrade(req).filter {
      _.equalsIgnoreCase(HttpHeaders.Values.WEBSOCKET)
    }.headOption.map { _ => req }
}

private [websockets] object WSLocation {
  def apply[T](r: HttpRequest[T]) = "ws://%s%s" format(Host(r).get, r.uri.split('?')(0))
}

trait Plan extends SimpleChannelUpstreamHandler {

  import java.security.MessageDigest
  import jnetty.channel.{ChannelFuture, ChannelFutureListener,
                         ChannelStateEvent, ExceptionEvent}
  import jnetty.buffer.ChannelBuffers
  import jnetty.handler.codec.http.websocket.{DefaultWebSocketFrame, WebSocketFrame,
                                             WebSocketFrameDecoder, WebSocketFrameEncoder}<commit_msg>leave any query string in WSLocation<commit_after>package unfiltered.netty.websockets

import unfiltered.request._
import unfiltered.response._
import unfiltered.netty._

import org.jboss.{netty => jnetty}
import jnetty.handler.codec.http.HttpHeaders
import jnetty.channel.{Channel, ChannelHandlerContext, MessageEvent, SimpleChannelUpstreamHandler}
import jnetty.buffer.ChannelBuffer

object Plan {
  type SocketIntent = PartialFunction[SocketCallback, Unit]
  type Intent = PartialFunction[RequestBinding, SocketIntent]
  type Pass = (ChannelHandlerContext, MessageEvent) => Unit
}

private [websockets] object ProtocolRequestHeader extends StringHeader(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL)
private [websockets] object SecKeyOne extends StringHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY1)
private [websockets] object SecKeyTwo extends StringHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY2)
private [websockets] object OriginRequestHeader extends StringHeader(HttpHeaders.Names.ORIGIN)
private [websockets] object ConnectionUpgrade {
  def unapply[T](req: HttpRequest[T]) =
    unfiltered.request.Connection(req).filter {
      _.equalsIgnoreCase(HttpHeaders.Values.UPGRADE)
    }
}

private [websockets] object UpgradeWebsockets {
  def unapply[T](req: HttpRequest[T]) =
    Upgrade(req).filter {
      _.equalsIgnoreCase(HttpHeaders.Values.WEBSOCKET)
    }.headOption.map { _ => req }
}

private [websockets] object WSLocation {
  def apply[T](r: HttpRequest[T]) = "ws://%s%s" format(Host(r).get, r.uri)
}

trait Plan extends SimpleChannelUpstreamHandler {

  import java.security.MessageDigest
  import jnetty.channel.{ChannelFuture, ChannelFutureListener,
                         ChannelStateEvent, ExceptionEvent}
  import jnetty.buffer.ChannelBuffers
  import jnetty.handler.codec.http.websocket.{DefaultWebSocketFrame, WebSocketFrame,
                                             WebSocketFrameDecoder, WebSocketFrameEncoder}
{'fraction_non_alphanumeric': 0.0901788027986525, 'fraction_numerical': 0.001295672454003628, 'mean_word_length': 5.176, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6630796', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1102, 'n_words': 218}