Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added necessary widens to support multiple environments #2567

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ trait ZioHttpInterpreter[R] {

def zioHttpServerOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default

def toHttp(se: ZServerEndpoint[R, ZioStreams]): Http[R, Throwable, Request, Response] =
def toHttp[R2](se: ZServerEndpoint[R2, ZioStreams]): Http[R & R2, Throwable, Request, Response] =
toHttp(List(se))

def toHttp(ses: List[ZServerEndpoint[R, ZioStreams]]): Http[R, Throwable, Request, Response] = {
implicit val bodyListener: ZioHttpBodyListener[R] = new ZioHttpBodyListener[R]
implicit val monadError: MonadError[RIO[R, *]] = new RIOMonadError[R]
val interpreter = new ServerInterpreter[ZioStreams, RIO[R, *], ZioHttpResponseBody, ZioStreams](
FilterServerEndpoints(ses),
new ZioHttpRequestBody(zioHttpServerOptions),
def toHttp[R2](ses: List[ZServerEndpoint[R2, ZioStreams]]): Http[R & R2, Throwable, Request, Response] = {
implicit val bodyListener: ZioHttpBodyListener[R & R2] = new ZioHttpBodyListener[R & R2]
implicit val monadError: MonadError[RIO[R & R2, *]] = new RIOMonadError[R & R2]
val widenedSes = ses.map(_.widen[R & R2])
val widenedServerOptions = zioHttpServerOptions.widen[R & R2]

val interpreter = new ServerInterpreter[ZioStreams, RIO[R & R2, *], ZioHttpResponseBody, ZioStreams](
FilterServerEndpoints[ZioStreams, RIO[R & R2, *]](widenedSes),
new ZioHttpRequestBody(widenedServerOptions),
new ZioHttpToResponseBody,
RejectInterceptor.disableWhenSingleEndpoint(zioHttpServerOptions.interceptors, ses),
RejectInterceptor.disableWhenSingleEndpoint(widenedServerOptions.interceptors, widenedSes),
zioHttpServerOptions.deleteFile
)

Expand Down Expand Up @@ -60,9 +63,14 @@ trait ZioHttpInterpreter[R] {
}

object ZioHttpInterpreter {
def apply[R](serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]): ZioHttpInterpreter[R] = {
def apply[R](serverOptions: ZioHttpServerOptions[R]): ZioHttpInterpreter[R] = {
new ZioHttpInterpreter[R] {
override def zioHttpServerOptions: ZioHttpServerOptions[R] = serverOptions
}
}
def apply(): ZioHttpInterpreter[Any] = {
new ZioHttpInterpreter[Any] {
override def zioHttpServerOptions: ZioHttpServerOptions[Any] = ZioHttpServerOptions.default[Any]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ case class ZioHttpServerOptions[R](
copy(interceptors = i :: interceptors)
def appendInterceptor(i: Interceptor[RIO[R, *]]): ZioHttpServerOptions[R] =
copy(interceptors = interceptors :+ i)

def widen[R2 <: R]: ZioHttpServerOptions[R2] = this.asInstanceOf[ZioHttpServerOptions[R2]]
}

object ZioHttpServerOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ trait ZioHttpInterpreter[R] {

def zioHttpServerOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default

def toHttp(se: ZServerEndpoint[R, ZioStreams]): Http[R, Throwable, Request, Response] =
def toHttp[R2](se: ZServerEndpoint[R2, ZioStreams]): Http[R & R2, Throwable, Request, Response] =
toHttp(List(se))

def toHttp(ses: List[ZServerEndpoint[R, ZioStreams]]): Http[R, Throwable, Request, Response] = {
implicit val bodyListener: ZioHttpBodyListener[R] = new ZioHttpBodyListener[R]
implicit val monadError: MonadError[RIO[R, *]] = new RIOMonadError[R]
val interpreter = new ServerInterpreter[ZioStreams, RIO[R, *], ZioHttpResponseBody, ZioStreams](
FilterServerEndpoints(ses),
new ZioHttpRequestBody(zioHttpServerOptions),
def toHttp[R2](ses: List[ZServerEndpoint[R2, ZioStreams]]): Http[R & R2, Throwable, Request, Response] = {
implicit val bodyListener: ZioHttpBodyListener[R & R2] = new ZioHttpBodyListener[R & R2]
implicit val monadError: MonadError[RIO[R & R2, *]] = new RIOMonadError[R & R2]
val widenedSes = ses.map(_.widen[R & R2])
val widenedServerOptions = zioHttpServerOptions.widen[R & R2]

val interpreter = new ServerInterpreter[ZioStreams, RIO[R & R2, *], ZioHttpResponseBody, ZioStreams](
FilterServerEndpoints(widenedSes),
new ZioHttpRequestBody(widenedServerOptions),
new ZioHttpToResponseBody,
RejectInterceptor.disableWhenSingleEndpoint(zioHttpServerOptions.interceptors, ses),
RejectInterceptor.disableWhenSingleEndpoint(widenedServerOptions.interceptors, widenedSes),
zioHttpServerOptions.deleteFile
)

Expand Down Expand Up @@ -63,9 +66,15 @@ trait ZioHttpInterpreter[R] {
}

object ZioHttpInterpreter {
def apply[R](serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]): ZioHttpInterpreter[R] = {
def apply[R](serverOptions: ZioHttpServerOptions[R]): ZioHttpInterpreter[R] = {
new ZioHttpInterpreter[R] {
override def zioHttpServerOptions: ZioHttpServerOptions[R] = serverOptions
}
}

def apply(): ZioHttpInterpreter[Any] = {
new ZioHttpInterpreter[Any] {
override def zioHttpServerOptions: ZioHttpServerOptions[Any] = ZioHttpServerOptions.default[Any]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ case class ZioHttpServerOptions[R](
copy(interceptors = i :: interceptors)
def appendInterceptor(i: Interceptor[RIO[R, *]]): ZioHttpServerOptions[R] =
copy(interceptors = interceptors :+ i)

def widen[R2 <: R]: ZioHttpServerOptions[R2] = this.asInstanceOf[ZioHttpServerOptions[R2]]
}

object ZioHttpServerOptions {
Expand Down