Skip to content

Commit

Permalink
http (fix): Replace Rx[ServerSentEvent] to Rx[Unit] in the generated …
Browse files Browse the repository at this point in the history
…async client (#3860)

As Rx[ServerSentEvent] can't be read asynchronously inJS environments
  • Loading branch information
xerial authored Mar 5, 2025
1 parent 8d3306c commit 1b91005
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
*/
package wvlet.airframe.http.codegen

import java.util.Locale
import wvlet.airframe.http.Router.unwrapFuture
import wvlet.airframe.http.{HttpMethod, Router, RxRouter}
import wvlet.airframe.http.codegen.RouteAnalyzer.RouteAnalysisResult
import wvlet.airframe.http.codegen.client.HttpClientGenerator
import wvlet.airframe.http.codegen.client.HttpClientGenerator.fullTypeNameOf
import wvlet.airframe.http.router.Route
import wvlet.airframe.http.{HttpMethod, Router, RxRouter, ServerSentEvent}
import wvlet.airframe.rx.Rx
import wvlet.airframe.surface.{GenericSurface, HigherKindedTypeSurface, MethodParameter, Parameter, Surface, TypeName}
import wvlet.airframe.surface.*
import wvlet.log.LogSupport
import wvlet.airframe.http.router.{HttpRequestMapper, Route}

import java.util.Locale

/**
* Generate an intermediate representation (IR) of Scala HTTP client code from a given airframe-http interface
Expand Down Expand Up @@ -189,7 +190,12 @@ object HttpClientIR extends LogSupport {
val isRxResponse = returnType.rawType.isAssignableFrom(classOf[Rx[_]]) && returnType.typeArgs.size == 1
if (isRxResponse) {
// for methods returning Rx[A], extract A
returnType.typeArgs(0)
val tpe = returnType.typeArgs(0)
if (tpe.rawType == classOf[ServerSentEvent]) {
// For SSE, return empty result as the events will be handled by the event handler
Surface.of[Unit]
} else
tpe
} else {
returnType
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* limitations under the License.
*/
package wvlet.airframe.http.codegen.client
import wvlet.airframe.http.{Http, HttpMethod}
import wvlet.airframe.http.HttpMessage.Response
import wvlet.airframe.http.{Http, HttpMethod, ServerSentEvent}
import wvlet.airframe.http.codegen.HttpClientIR
import wvlet.airframe.http.codegen.HttpClientIR.{ClientMethodDef, ClientServiceDef}
import wvlet.airframe.http.codegen.client.HttpClientGenerator.RichSurface
Expand Down

0 comments on commit 1b91005

Please # to comment.