<commit_before>package unfiltered.netty

import unfiltered.util.{ RunnableServer, PlanServer }

import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.{
  ChannelFutureListener,
  ChannelHandler,
  ChannelHandlerContext,
  ChannelInboundHandlerAdapter,
  ChannelInitializer,
  ChannelOption,
  ChannelPipeline,
  EventLoopGroup
}
import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel.group.{ ChannelGroup, DefaultChannelGroup }
import io.netty.channel.nio.{ NioEventLoop, NioEventLoopGroup }
import io.netty.channel.socket.SocketChannel
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.handler.codec.http.{
  DefaultHttpResponse,
  HttpContent,
  HttpMessage,
  HttpObjectAggregator,
  HttpRequestDecoder,
  HttpResponseEncoder,
  HttpResponseStatus }
import io.netty.handler.stream.ChunkedWriteHandler
import io.netty.util.ReferenceCountUtil
import io.netty.util.concurrent.GlobalEventExecutor

import java.lang.{ Boolean => JBoolean, Integer => JInteger }
import java.net.{ InetSocketAddress, URL }
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicInteger

/** Default implementation of the Server trait. If you want to use a
 * custom pipeline factory it's better to extend Server directly. */
case class Http(
  port: Int, host: String,
  handlers: List[() => ChannelHandler],
  beforeStopBlock: () => Unit,
  chunkSize: Int = 1048576)
  extends HttpServer with DefaultServerInit { self =>
  type ServerBuilder = Http

  def initializer: ChannelInitializer[SocketChannel] =
    new ServerInit(channels, handlers, chunkSize)

  override def makePlan(h: => ChannelHandler) =
    Http(port, host, { () => h } :: handlers, beforeStopBlock)
  /** Convenience method for adding a HttpObjectAggregator to the
   *  pipeline. Supports chunked request bodies up to the specified
   *  maximum bytes. Without this aggregator, chunked requests will
   *  not not be handled. */
  def chunked(size: Int = 1048576) =
    copy(chunkSize = size)

  def handler(h: ChannelHandler) = makePlan(h)

  def beforeStop(block: => Unit) =
    Http(port, host, handlers, { () => beforeStopBlock(); block })
}

/** Factory for creating Http servers */
object Http {
  def apply(port: Int, host: String): Http =
    Http(port, host, Nil, () => ())
  def apply(port: Int): Http =
    Http(port, "0.0.0.0")
  /** bind to a the loopback interface only */
  def local(port: Int): Http =
    Http(port, "127.0.0.1")
  /** bind to any available port on the loopback interface */
  def anylocal = local(unfiltered.util.Port.any)
}

/** An HTTP or HTTPS server */
trait HttpServer extends Server with PlanServer[ChannelHandler] {

  /** block of code to be invoked when the server is stopped,
   *  before connectons are closed */
  def beforeStopBlock: () => Unit<commit_msg>propegate case class values properly. fixes #224<commit_after>package unfiltered.netty

import unfiltered.util.{ RunnableServer, PlanServer }

import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.{
  ChannelFutureListener,
  ChannelHandler,
  ChannelHandlerContext,
  ChannelInboundHandlerAdapter,
  ChannelInitializer,
  ChannelOption,
  ChannelPipeline,
  EventLoopGroup
}
import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel.group.{ ChannelGroup, DefaultChannelGroup }
import io.netty.channel.nio.{ NioEventLoop, NioEventLoopGroup }
import io.netty.channel.socket.SocketChannel
import io.netty.channel.socket.nio.NioServerSocketChannel
import io.netty.handler.codec.http.{
  DefaultHttpResponse,
  HttpContent,
  HttpMessage,
  HttpObjectAggregator,
  HttpRequestDecoder,
  HttpResponseEncoder,
  HttpResponseStatus }
import io.netty.handler.stream.ChunkedWriteHandler
import io.netty.util.ReferenceCountUtil
import io.netty.util.concurrent.GlobalEventExecutor

import java.lang.{ Boolean => JBoolean, Integer => JInteger }
import java.net.{ InetSocketAddress, URL }
import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicInteger

/** Default implementation of the Server trait. If you want to use a
 * custom pipeline factory it's better to extend Server directly. */
case class Http(
  port: Int, host: String,
  handlers: List[() => ChannelHandler],
  beforeStopBlock: () => Unit,
  chunkSize: Int = 1048576)
  extends HttpServer with DefaultServerInit { self =>
  type ServerBuilder = Http

  def initializer: ChannelInitializer[SocketChannel] =
    new ServerInit(channels, handlers, chunkSize)

  override def makePlan(h: => ChannelHandler) =
    copy(handlers = { () => h } :: handlers)

  /** Convenience method for adding a HttpObjectAggregator to the
   *  pipeline. Supports chunked request bodies up to the specified
   *  maximum bytes. Without this aggregator, chunked requests will
   *  not not be handled. */
  def chunked(size: Int = 1048576) =
    copy(chunkSize = size)

  def handler(h: ChannelHandler) = makePlan(h)

  def beforeStop(block: => Unit) =
    copy(beforeStopBlock = { () => beforeStopBlock(); block })
}

/** Factory for creating Http servers */
object Http {
  def apply(port: Int, host: String): Http =
    Http(port, host, Nil, () => ())
  def apply(port: Int): Http =
    Http(port, "0.0.0.0")
  /** bind to a the loopback interface only */
  def local(port: Int): Http =
    Http(port, "127.0.0.1")
  /** bind to any available port on the loopback interface */
  def anylocal = local(unfiltered.util.Port.any)
}

/** An HTTP or HTTPS server */
trait HttpServer extends Server with PlanServer[ChannelHandler] {

  /** block of code to be invoked when the server is stopped,
   *  before connectons are closed */
  def beforeStopBlock: () => Unit
{'fraction_non_alphanumeric': 0.10260930888575458, 'fraction_numerical': 0.008991537376586742, 'mean_word_length': 4.418338108882521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '811574', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1667, 'n_words': 489}