Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send back response data while still processing #1466

Open
bilbothebaggins opened this issue Jan 10, 2025 · 4 comments
Open

Send back response data while still processing #1466

bilbothebaggins opened this issue Jan 10, 2025 · 4 comments

Comments

@bilbothebaggins
Copy link

I wanted to implement a very simple HTTP server to query some large/slow datasets in our buildsystem.
This means that generating the data for a GET request can take many seconds.

I noticed that the programming model with all Write-PodeXXXResponsefunctions - most collapsing to Write-PodeTextResponse as far as I can tell - is to collect all the data and then send back the headers and body in one go at the end of the route.

This is quite inconvenient in my case.
I would have preferred to be able to send the response data incrementally.

A hypothetical API:

# Do some input validation
...
# Start fetching data
...
# Send response headers (it's fine to do this in one block)
Write-PodeHeaders ...
while (...) {
  # Once data available
  Write-PodeBodyTextPart $firstPartOfData
  ...
}
...

I know I could start fiddling with Response.Send() or the underlying request, but it seems this would be very flaky.

Am I maybe missing something?

@mdaneri
Copy link
Contributor

mdaneri commented Jan 12, 2025

@bilbothebaggins
Copy link
Author

Use https://badgerati.github.io/Pode/Tutorials/Routes/Utilities/SSE/ for that

Thanks for the tip.

I note at first glance:

For a request to be convertible, it must have an Accept HTTP request header value of text/event-stream

Did you mean to say SSE would be a drop-in, or rather that the use-case can be adapted to use SSE?

@mdaneri
Copy link
Contributor

mdaneri commented Jan 13, 2025

I responded a bit hastily. SSE is a web browser feature. If you need to feed a webpage with data, this is the most technically sound solution to use. However, if your request is not coming from a web page, other methods like a multipart stream can be employed.

@bilbothebaggins
Copy link
Author

Hmm ... isn't multipart/form-data an upload feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants