Skip to content

Commit 8c50705

Browse files
committed
ok
1 parent 80c54f8 commit 8c50705

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/api/Elastic.Documentation.Api.Infrastructure/MappingsExtensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@ public static void MapElasticDocsApiEndpoints(this IEndpointRouteBuilder group)
2424
private static void MapAskAiEndpoint(IEndpointRouteBuilder group)
2525
{
2626
var askAiGroup = group.MapGroup("/ask-ai");
27-
_ = askAiGroup.MapPost("/stream", async (AskAiRequest askAiRequest, AskAiUsecase askAiUsecase, Cancel ctx) =>
27+
_ = askAiGroup.MapPost("/stream", async (HttpContext context, AskAiRequest askAiRequest, AskAiUsecase askAiUsecase, Cancel ctx) =>
2828
{
29+
// Set response headers IMMEDIATELY before calling the usecase
30+
// This makes the browser show the request as "active" instead of "pending"
31+
context.Response.ContentType = "text/event-stream";
32+
context.Response.Headers.CacheControl = "no-cache";
33+
context.Response.Headers.Connection = "keep-alive";
34+
35+
// Flush headers to the client immediately
36+
await context.Response.StartAsync(ctx);
37+
2938
var stream = await askAiUsecase.AskAi(askAiRequest, ctx);
3039

31-
// Configure response headers for optimal streaming
32-
return Results.Stream(stream, "text/event-stream");
40+
// Stream the response
41+
await stream.CopyToAsync(context.Response.Body, ctx);
3342
});
3443
}
3544

0 commit comments

Comments
 (0)