Skip to content

Commit

Permalink
Fix #393
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Nov 12, 2019
1 parent 5114e08 commit 3162ec6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion otoroshi/app/env/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ class Env(val configuration: Configuration,
removeHeadersOut = Seq.empty,
accessValidator = AccessValidatorRef(),
missingOnlyHeadersIn = Map.empty,
missingOnlyHeadersOut = Map.empty
missingOnlyHeadersOut = Map.empty,
stripPath = true
)

lazy val otoroshiVersion = "1.4.14-dev"
Expand Down
1 change: 1 addition & 0 deletions otoroshi/app/gateway/handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ class GatewayRequestHandler(snowMonkey: SnowMonkey,
val uriParts = rawUri.split("/").toSeq
val uri: String =
descriptor.matchingRoot
.filter(_ => descriptor.stripPath)
.map(m => req.relativeUri.replace(m, ""))
.getOrElse(rawUri)
val scheme =
Expand Down
5 changes: 4 additions & 1 deletion otoroshi/app/gateway/websockets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,10 @@ class WebSocketHandler()(implicit env: Env) {
val rawUri = req.relativeUri.substring(1)
val uriParts = rawUri.split("/").toSeq
val uri: String =
descriptor.matchingRoot.map(m => req.relativeUri.replace(m, "")).getOrElse(rawUri)
descriptor.matchingRoot
.filter(_ => descriptor.stripPath)
.map(m => req.relativeUri.replace(m, ""))
.getOrElse(rawUri)
// val index = reqCounter.incrementAndGet() % (if (descriptor.targets.nonEmpty) descriptor.targets.size else 1)
// // Round robin loadbalancing is happening here !!!!!
// val target = descriptor.targets.apply(index.toInt)
Expand Down
6 changes: 5 additions & 1 deletion otoroshi/app/models/descriptor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ case class ServiceDescriptor(
targets: Seq[Target] = Seq.empty[Target],
root: String = "/",
matchingRoot: Option[String] = None,
stripPath: Boolean = true,
localHost: String = "localhost:8080",
localScheme: String = "http",
redirectToLocal: Boolean = false,
Expand Down Expand Up @@ -2309,6 +2310,7 @@ object ServiceDescriptor {
localScheme = (json \ "localScheme").asOpt[String].getOrElse("http"),
redirectToLocal = (json \ "redirectToLocal").asOpt[Boolean].getOrElse(false),
enabled = (json \ "enabled").asOpt[Boolean].getOrElse(true),
stripPath = (json \ "stripPath").asOpt[Boolean].getOrElse(true),
userFacing = (json \ "userFacing").asOpt[Boolean].getOrElse(false),
privateApp = (json \ "privateApp").asOpt[Boolean].getOrElse(false),
forceHttps = (json \ "forceHttps").asOpt[Boolean].getOrElse(true),
Expand Down Expand Up @@ -2416,6 +2418,7 @@ object ServiceDescriptor {
"targets" -> JsArray(sd.targets.map(_.toJson)),
"root" -> sd.root,
"matchingRoot" -> sd.matchingRoot,
"stripPath" -> sd.stripPath,
"localHost" -> sd.localHost,
"localScheme" -> sd.localScheme,
"redirectToLocal" -> sd.redirectToLocal,
Expand Down Expand Up @@ -2520,7 +2523,8 @@ trait ServiceDescriptorDataStore extends BasicStore[ServiceDescriptor] {
removeHeadersOut = Seq.empty,
accessValidator = AccessValidatorRef(),
missingOnlyHeadersIn = Map.empty,
missingOnlyHeadersOut = Map.empty
missingOnlyHeadersOut = Map.empty,
stripPath = true
)
def updateMetrics(id: String,
callDuration: Long,
Expand Down
6 changes: 6 additions & 0 deletions otoroshi/javascript/src/pages/ServicePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,12 @@ export class ServicePage extends Component {
.matchingRoot || ''}/`}
/>
)}
<BooleanInput
label="Strip path"
value={this.state.service.stripPath}
help="When matching, strip the matching prefix from the upstream request URL. Defaults to true"
onChange={e => this.changeTheValue('stripPath', e)}
/>
</Collapse>
<Collapse
notVisible={this.state.service.tcpUdpTunneling}
Expand Down

0 comments on commit 3162ec6

Please sign in to comment.