@@ -200,21 +200,7 @@ func handleFunctionURLStreaming(ctx context.Context, event events.LambdaFunction
200
200
resCh := make (chan * events.LambdaFunctionURLStreamingResponse )
201
201
errCh := make (chan error )
202
202
203
- go func (resCh chan <- * events.LambdaFunctionURLStreamingResponse , errCh chan <- error ) {
204
- defer close (resCh )
205
- defer close (errCh )
206
-
207
- w := functionURLStreamingResponseWriter {
208
- headers : make (http.Header ),
209
- resCh : resCh ,
210
- }
211
-
212
- defer w .Close ()
213
-
214
- if err := adapter (ctx , req , & w ); err != nil {
215
- errCh <- err
216
- }
217
- }(resCh , errCh )
203
+ go processRequestFunctionURLStreaming (ctx , req , adapter , resCh , errCh )
218
204
219
205
select {
220
206
case res := <- resCh :
@@ -226,6 +212,25 @@ func handleFunctionURLStreaming(ctx context.Context, event events.LambdaFunction
226
212
}
227
213
}
228
214
215
+ func processRequestFunctionURLStreaming (ctx context.Context , req * http.Request , adapter AdapterFunc , resCh chan <- * events.LambdaFunctionURLStreamingResponse , errCh chan <- error ) {
216
+ defer close (resCh )
217
+ defer close (errCh )
218
+
219
+ ctx , cancel := context .WithCancel (ctx )
220
+ defer cancel ()
221
+
222
+ w := functionURLStreamingResponseWriter {
223
+ headers : make (http.Header ),
224
+ resCh : resCh ,
225
+ }
226
+
227
+ defer w .Close ()
228
+
229
+ if err := adapter (ctx , req , & w ); err != nil {
230
+ errCh <- err
231
+ }
232
+ }
233
+
229
234
func NewFunctionURLStreamingHandler (adapter AdapterFunc ) func (context.Context , events.LambdaFunctionURLRequest ) (* events.LambdaFunctionURLStreamingResponse , error ) {
230
235
return NewHandler (handleFunctionURLStreaming , adapter )
231
236
}
0 commit comments