Skip to content

Commit f9e3ebf

Browse files
committed
feat: enhance streaming support
1 parent 25b346a commit f9e3ebf

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

handler/functionurl.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,7 @@ func handleFunctionURLStreaming(ctx context.Context, event events.LambdaFunction
200200
resCh := make(chan *events.LambdaFunctionURLStreamingResponse)
201201
errCh := make(chan error)
202202

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)
218204

219205
select {
220206
case res := <-resCh:
@@ -226,6 +212,25 @@ func handleFunctionURLStreaming(ctx context.Context, event events.LambdaFunction
226212
}
227213
}
228214

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+
229234
func NewFunctionURLStreamingHandler(adapter AdapterFunc) func(context.Context, events.LambdaFunctionURLRequest) (*events.LambdaFunctionURLStreamingResponse, error) {
230235
return NewHandler(handleFunctionURLStreaming, adapter)
231236
}

0 commit comments

Comments
 (0)