File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -802,6 +802,26 @@ describe("onCallHandler", () => {
802
802
const data = [ `data: {"error":{"message":"INTERNAL","status":"INTERNAL"}}` ] ;
803
803
expect ( resp . body ) . to . equal ( [ ...data , "" ] . join ( "\n" ) ) ;
804
804
} ) ;
805
+
806
+ it ( "always returns error for v1 callables" , async ( ) => {
807
+ const mockReq = mockRequest (
808
+ { message : "hello streaming" } ,
809
+ "application/json" ,
810
+ { } ,
811
+ { accept : "text/event-stream" }
812
+ ) as any ;
813
+ const fn = https . onCallHandler (
814
+ {
815
+ cors : { origin : true , methods : "POST" } ,
816
+ } ,
817
+ ( req , resp ) => {
818
+ return "hello world" ;
819
+ } ,
820
+ "gcfv1"
821
+ ) ;
822
+ const resp = await runHandler ( fn , mockReq ) ;
823
+ expect ( JSON . parse ( resp . body ) ) . to . deep . equal ( { "error" : { "status" : "INVALID_ARGUMENT" , "message" : "Unsupported Accept header 'text/event-stream'" } } ) ;
824
+ } ) ;
805
825
} ) ;
806
826
} ) ;
807
827
Original file line number Diff line number Diff line change @@ -788,7 +788,6 @@ function wrapOnCallHandler<Req = any, Res = any>(
788
788
throw new HttpsError ( 'invalid-argument' , "Unsupported Accept header 'text/event-stream'" )
789
789
}
790
790
791
-
792
791
const data : Req = decode ( req . body . data ) ;
793
792
let result : Res ;
794
793
if ( version === "gcfv1" ) {
@@ -839,11 +838,11 @@ function wrapOnCallHandler<Req = any, Res = any>(
839
838
840
839
const { status } = httpErr . httpErrorCode ;
841
840
const body = { error : httpErr . toJSON ( ) } ;
842
- if ( req . header ( "accept" ) === "text/event-stream" ) {
841
+ if ( version === "gcfv2" && req . header ( "accept" ) === "text/event-stream" ) {
843
842
res . send ( encodeSSE ( body ) ) ;
844
843
} else {
845
844
res . status ( status ) . send ( body ) ;
846
845
}
847
846
}
848
- } ;
849
- }
847
+ }
848
+ } ;
You can’t perform that action at this time.
0 commit comments