File tree 2 files changed +32
-1
lines changed 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -802,6 +802,31 @@ 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
+ ( ) => {
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
+ } ) ;
805
830
} ) ;
806
831
} ) ;
807
832
Original file line number Diff line number Diff line change @@ -782,6 +782,12 @@ function wrapOnCallHandler<Req = any, Res = any>(
782
782
}
783
783
784
784
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
+
785
791
const data : Req = decode ( req . body . data ) ;
786
792
let result : Res ;
787
793
if ( version === "gcfv1" ) {
@@ -832,7 +838,7 @@ function wrapOnCallHandler<Req = any, Res = any>(
832
838
833
839
const { status } = httpErr . httpErrorCode ;
834
840
const body = { error : httpErr . toJSON ( ) } ;
835
- if ( req . header ( "accept" ) === "text/event-stream" ) {
841
+ if ( version === "gcfv2" && req . header ( "accept" ) === "text/event-stream" ) {
836
842
res . send ( encodeSSE ( body ) ) ;
837
843
} else {
838
844
res . status ( status ) . send ( body ) ;
You can’t perform that action at this time.
0 commit comments