Skip to content

Commit c2c766c

Browse files
authored
Merge pull request #2754 from constantine2nd/develop
Readyness of the v7.0.0
2 parents 4fb65eb + 0b3327a commit c2c766c

File tree

8 files changed

+1824
-171
lines changed

8 files changed

+1824
-171
lines changed

obp-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@
521521
<junitxml>.</junitxml>
522522
<filereports>WDF TestSuite.txt</filereports>
523523
<argLine>-Drun.mode=test -XX:MaxMetaspaceSize=1g -Xms1g -Xmx2g --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.jar=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED</argLine>
524-
<tagsToExclude>code.external</tagsToExclude>
524+
<tagsToExclude>code.external,GetBanksPerf</tagsToExclude>
525525
<testFailureIgnore>${maven.test.failure.ignore}</testFailureIgnore>
526526
</configuration>
527527
<executions>

obp-api/src/main/scala/code/api/util/http4s/Http4sApp.scala

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package code.api.util.http4s
33
import cats.data.{Kleisli, OptionT}
44
import cats.effect.IO
55
import org.http4s._
6+
import org.typelevel.ci.CIString
67

78
/**
89
* Shared HTTP4S Application Builder
@@ -24,11 +25,37 @@ object Http4sApp {
2425

2526
type HttpF[A] = OptionT[IO, A]
2627

28+
// Handles all OPTIONS (CORS preflight) requests before they reach the Lift bridge.
29+
//
30+
// Without this, OPTIONS falls through the Kleisli chain to Http4sLiftWebBridge →
31+
// OBPAPI6_0_0's `this.serve({case OPTIONS => corsResponse})`, which pays full Lift
32+
// overhead (body buffering, S.init) for every preflight. More critically, when the
33+
// Lift bridge is eventually removed, CORS would break silently. Headers match the
34+
// corsResponse defined in v4/v5/v6 Lift endpoints.
35+
private val corsHandler: HttpRoutes[IO] = HttpRoutes[IO] { req =>
36+
if (req.method == Method.OPTIONS) {
37+
OptionT.liftF(
38+
IO.pure(
39+
Response[IO](Status.NoContent)
40+
.putHeaders(
41+
Header.Raw(CIString("Access-Control-Allow-Origin"), "*"),
42+
Header.Raw(CIString("Access-Control-Allow-Methods"), "GET, POST, OPTIONS, PUT, PATCH, DELETE"),
43+
Header.Raw(CIString("Access-Control-Allow-Headers"), "*"),
44+
Header.Raw(CIString("Access-Control-Allow-Credentials"), "true")
45+
)
46+
)
47+
)
48+
} else {
49+
OptionT.none
50+
}
51+
}
52+
2753
/**
2854
* Build the base HTTP4S routes with priority-based routing
2955
*/
3056
private def baseServices: HttpRoutes[IO] = Kleisli[HttpF, Request[IO], Response[IO]] { req: Request[IO] =>
31-
StatusPage.routes.run(req)
57+
corsHandler.run(req)
58+
.orElse(StatusPage.routes.run(req))
3259
.orElse(code.api.v5_0_0.Http4s500.wrappedRoutesV500Services.run(req))
3360
.orElse(code.api.v7_0_0.Http4s700.wrappedRoutesV700Services.run(req))
3461
.orElse(code.api.berlin.group.v2.Http4sBGv2.wrappedRoutes.run(req))

obp-api/src/main/scala/code/api/util/http4s/Http4sSupport.scala

Lines changed: 317 additions & 37 deletions
Large diffs are not rendered by default.

obp-api/src/main/scala/code/api/util/http4s/ResourceDocMiddleware.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ object ResourceDocMiddleware extends MdcLoggable {
8585
* Finds the matching ResourceDoc, validates the request, and enriches CallContext.
8686
*/
8787
def apply(resourceDocs: ArrayBuffer[ResourceDoc]): HttpRoutes[IO] => HttpRoutes[IO] = { routes =>
88+
// Build the lookup index once per middleware instance (at startup), not per request.
89+
val resourceDocIndex = ResourceDocMatcher.buildIndex(resourceDocs)
8890
Kleisli[HttpF, Request[IO], Response[IO]] { req: Request[IO] =>
8991
val apiVersionFromPath = req.uri.path.segments.map(_.encoded).toList match {
9092
case apiPathZero :: version :: _ if apiPathZero == APIUtil.getPropsValue("apiPathZero", "obp") => version
9193
case _ => ApiShortVersions.`v7.0.0`.toString
9294
}
9395
// Build initial CallContext from request
9496
OptionT.liftF(Http4sCallContextBuilder.fromRequest(req, apiVersionFromPath)).flatMap { cc =>
95-
ResourceDocMatcher.findResourceDoc(req.method.name, req.uri.path, resourceDocs) match {
97+
ResourceDocMatcher.findResourceDoc(req.method.name, req.uri.path, resourceDocIndex) match {
9698
case Some(resourceDoc) =>
9799
val ccWithDoc = ResourceDocMatcher.attachToCallContext(cc, resourceDoc)
98100
val pathParams = ResourceDocMatcher.extractPathParams(req.uri.path, resourceDoc)

0 commit comments

Comments
 (0)