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", () => {
802802 const data = [ `data: {"error":{"message":"INTERNAL","status":"INTERNAL"}}` ] ;
803803 expect ( resp . body ) . to . equal ( [ ...data , "" ] . join ( "\n" ) ) ;
804804 } ) ;
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+ } ) ;
805825 } ) ;
806826} ) ;
807827
Original file line number Diff line number Diff line change @@ -788,7 +788,6 @@ function wrapOnCallHandler<Req = any, Res = any>(
788788 throw new HttpsError ( 'invalid-argument' , "Unsupported Accept header 'text/event-stream'" )
789789 }
790790
791-
792791 const data : Req = decode ( req . body . data ) ;
793792 let result : Res ;
794793 if ( version === "gcfv1" ) {
@@ -839,11 +838,11 @@ function wrapOnCallHandler<Req = any, Res = any>(
839838
840839 const { status } = httpErr . httpErrorCode ;
841840 const body = { error : httpErr . toJSON ( ) } ;
842- if ( req . header ( "accept" ) === "text/event-stream" ) {
841+ if ( version === "gcfv2" && req . header ( "accept" ) === "text/event-stream" ) {
843842 res . send ( encodeSSE ( body ) ) ;
844843 } else {
845844 res . status ( status ) . send ( body ) ;
846845 }
847846 }
848- } ;
849- }
847+ }
848+ } ;
You can’t perform that action at this time.
0 commit comments