Skip to content

Instantly share code, notes, and snippets.

@magnusart
Created March 22, 2015 12:22
Show Gist options
  • Save magnusart/5dfb824eb66e847d1f84 to your computer and use it in GitHub Desktop.
Save magnusart/5dfb824eb66e847d1f84 to your computer and use it in GitHub Desktop.
Shim to get akka-http M4 release to work.
package akka.http
import java.net.InetSocketAddress
import akka.http.engine.server.HttpServer.HttpServerPorts
import akka.stream.Graph
import com.typesafe.config.Config
import scala.collection.immutable
import scala.concurrent.Future
import akka.event.LoggingAdapter
import akka.util.ByteString
import akka.io.Inet
import akka.stream.ActorFlowMaterializer
import akka.stream.scaladsl._
import akka.http.engine.client.{ HttpClient, ClientConnectionSettings }
import akka.http.engine.server.{ HttpServer, ServerSettings }
import akka.http.model.{ ErrorInfo, HttpResponse, HttpRequest }
import akka.actor._
class HttpExtShim( config: Config )( implicit system: ActorSystem ) extends HttpExt( config )( system ) {
import Http._
override def bindAndstartHandlingWith( handler: Flow[HttpRequest, HttpResponse, _],
interface: String, port: Int = 80, backlog: Int = 100,
options: immutable.Traversable[Inet.SocketOption] = Nil,
settings: Option[ServerSettings] = None,
log: LoggingAdapter = system.log )( implicit fm: ActorFlowMaterializer ): Future[ServerBinding] = {
bind( interface, port, backlog, options, settings, log ).toMat( Sink.foreach { conn ⇒
conn.flow.join( handler ).run()
} )( Keep.left ).run()
}
}
object HttpShim extends ExtensionId[HttpExtShim] with ExtensionIdProvider {
import Http._
def apply()( implicit system: ActorSystem ): HttpExtShim = super.apply( system )
def lookup() = HttpShim
def createExtension( system: ExtendedActorSystem ): HttpExtShim =
new HttpExtShim( system.settings.config getConfig "akka.http" )( system )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment