All Downloads are FREE. Search and download functionalities are using the official Maven repository.

zhttp.service.RequestBodyHandler.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0-RC11
Show newest version
package zhttp.service
import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler}
import io.netty.handler.codec.http.{HttpContent, LastHttpContent}
import zhttp.http.HttpData.{UnsafeChannel, UnsafeContent}

final class RequestBodyHandler(val callback: UnsafeChannel => UnsafeContent => Unit)
    extends SimpleChannelInboundHandler[HttpContent](false) { self =>

  private var onMessage: UnsafeContent => Unit = _

  override def channelRead0(ctx: ChannelHandlerContext, msg: HttpContent): Unit = {
    self.onMessage(new UnsafeContent(msg))
    if (msg.isInstanceOf[LastHttpContent]) {
      ctx.channel().pipeline().remove(self): Unit
    }
  }

  override def handlerAdded(ctx: ChannelHandlerContext): Unit = {
    self.onMessage = callback(new UnsafeChannel(ctx))
    ctx.read(): Unit
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy