How about this:

(ctx.getChannel.getLocalAddress, ctx.getChannel.getRemoteAddress) match {
  case (l: InetSocketAddress, r: InetSocketAddress) if l.getAddress == r.getAddress => new InetSocketAddress("localhost", r.getPort)
  case (_, r: InetSocketAddress) => r
}