File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -802,6 +802,31 @@ 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+ ( ) => {
818+ return "hello world" ;
819+ } ,
820+ "gcfv1"
821+ ) ;
822+ const resp = await runHandler ( fn , mockReq ) ;
823+ expect ( JSON . parse ( resp . body ) ) . to . deep . equal ( {
824+ error : {
825+ status : "INVALID_ARGUMENT" ,
826+ message : "Unsupported Accept header 'text/event-stream'" ,
827+ } ,
828+ } ) ;
829+ } ) ;
805830 } ) ;
806831} ) ;
807832
Original file line number Diff line number Diff line change @@ -782,6 +782,12 @@ function wrapOnCallHandler<Req = any, Res = any>(
782782 }
783783
784784 const acceptsStreaming = req . header ( "accept" ) === "text/event-stream" ;
785+
786+ if ( acceptsStreaming && version === "gcfv1" ) {
787+ // streaming responses are not supported in v1 callable
788+ throw new HttpsError ( "invalid-argument" , "Unsupported Accept header 'text/event-stream'" ) ;
789+ }
790+
785791 const data : Req = decode ( req . body . data ) ;
786792 let result : Res ;
787793 if ( version === "gcfv1" ) {
@@ -832,7 +838,7 @@ function wrapOnCallHandler<Req = any, Res = any>(
832838
833839 const { status } = httpErr . httpErrorCode ;
834840 const body = { error : httpErr . toJSON ( ) } ;
835- if ( req . header ( "accept" ) === "text/event-stream" ) {
841+ if ( version === "gcfv2" && req . header ( "accept" ) === "text/event-stream" ) {
836842 res . send ( encodeSSE ( body ) ) ;
837843 } else {
838844 res . status ( status ) . send ( body ) ;
You can’t perform that action at this time.
0 commit comments