Skip to content

Commit

Permalink
Better URL support and proxying of SSL connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Dec 15, 2016
1 parent c758372 commit e64ba55
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
15 changes: 12 additions & 3 deletions core/jvm/src/main/scala/org/hyperscala/HandlerBuilder.scala
@@ -1,11 +1,15 @@
package org.hyperscala

import java.io.File
import java.net.URI

import io.undertow.Handlers
import io.undertow.server.handlers.proxy.SimpleProxyClientProvider
import io.undertow.protocols.ssl.UndertowXnioSsl
import io.undertow.server.handlers.proxy.LoadBalancingProxyClient
import io.undertow.server.{HttpHandler, HttpServerExchange}
import io.undertow.util.Headers
import org.hyperscala.util.SSLUtil
import org.xnio.{OptionMap, Xnio}

class HandlerBuilder(matcher: PartialFunction[URL, Boolean] = Map.empty,
handler: (URL, HttpServerExchange) => Unit = (url, exchange) => Unit,
Expand All @@ -32,8 +36,13 @@ class HandlerBuilder(matcher: PartialFunction[URL, Boolean] = Map.empty,
new HandlerBuilder(matcher, h, priority)
}

def withProxy(uri: URI): HandlerBuilder = {
val proxyClient = new SimpleProxyClientProvider(uri)
def withProxy(uri: URI, keyStoreFile: Option[File] = None, keyStorePassword: String = "password"): HandlerBuilder = {
val proxyClient = new LoadBalancingProxyClient
val ssl = keyStoreFile.map { file =>
val sslContext = SSLUtil.createSSLContext(file, keyStorePassword)
new UndertowXnioSsl(Xnio.getInstance(), OptionMap.EMPTY, sslContext)
}
proxyClient.addHost(uri, ssl.orNull)
val proxyHandler = Handlers.proxyHandler(proxyClient)
val h = (url: URL, exchange: HttpServerExchange) => proxyHandler.handleRequest(exchange)
new HandlerBuilder(matcher, h, priority)
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/org/hyperscala/URL.scala
Expand Up @@ -51,6 +51,10 @@ case class URL(protocol: Protocol = Protocol.Http,
if (portBreak != -1) {
port = s.substring(portBreak + 1).toInt
s = s.substring(0, portBreak)
} else if (protocol == Protocol.Http) {
port = 80
} else if (protocol == Protocol.Https) {
port = 443
}
if (s.nonEmpty) {
host = s
Expand Down
12 changes: 6 additions & 6 deletions project/HyperscalaBuild.scala
Expand Up @@ -13,7 +13,7 @@ object HyperscalaBuild extends Build {
.settings(
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _),
libraryDependencies ++= Seq(
"com.outr.scribe" %%% "scribe" % Dependencies.scribe,
"com.outr" %%% "scribe" % Dependencies.scribe,
"com.lihaoyi" %%% "upickle" % Dependencies.uPickle,
"com.outr" %%% "metarx" % Dependencies.metaRx,
"org.scalatest" %%% "scalatest" % Dependencies.scalaTest % "test"
Expand All @@ -29,7 +29,7 @@ object HyperscalaBuild extends Build {
)
.jvmSettings(
libraryDependencies ++= Seq(
"com.outr.scribe" %% "scribe-slf4j" % Dependencies.scribe,
"com.outr" %% "scribe-slf4j" % Dependencies.scribe,
"io.undertow" % "undertow-core" % Dependencies.undertow
)
)
Expand All @@ -42,7 +42,7 @@ object HyperscalaBuild extends Build {
.settings(
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _),
libraryDependencies ++= Seq(
"com.outr.scribe" %%% "scribe" % Dependencies.scribe,
"com.outr" %%% "scribe" % Dependencies.scribe,
"com.lihaoyi" %%% "upickle" % Dependencies.uPickle,
"com.outr" %%% "metarx" % Dependencies.metaRx,
"org.scalatest" %%% "scalatest" % Dependencies.scalaTest % "test"
Expand All @@ -58,7 +58,7 @@ object HyperscalaBuild extends Build {
)
.jvmSettings(
libraryDependencies ++= Seq(
"com.outr.scribe" %% "scribe-slf4j" % Dependencies.scribe,
"com.outr" %% "scribe-slf4j" % Dependencies.scribe,
"io.undertow" % "undertow-core" % Dependencies.undertow
)
)
Expand Down Expand Up @@ -120,7 +120,7 @@ object HyperscalaBuild extends Build {
object Details {
val organization = "org.hyperscala"
val name = "hyperscala"
val version = "2.1.5"
val version = "2.1.6-SNAPSHOT"
val url = "http://hyperscala.org"
val licenseType = "MIT"
val licenseURL = "http://opensource.org/licenses/MIT"
Expand All @@ -136,7 +136,7 @@ object Details {
}

object Dependencies {
val scribe = "1.2.5"
val scribe = "1.2.6"
val undertow = "1.4.7.Final"
val uPickle = "0.4.1"
val scalaTest = "3.0.0-M16-SNAP4"
Expand Down

0 comments on commit e64ba55

Please sign in to comment.