Skip to content
New issue

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

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

Already on GitHub? # to your account

Add example for streaming a file in Rust #1930

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

radu-matei
Copy link
Member

This commit adds a simple example showing file streaming in Rust.

Signed-off-by: Radu Matei <radu@fermyon.com>
examples/wasi-http-streaming-file/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +13 to +17
async fn handler(req: IncomingRequest, res: ResponseOutparam) {
stream_file(req, res).await.unwrap();
}

async fn stream_file(_req: IncomingRequest, res: ResponseOutparam) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async fn handler(req: IncomingRequest, res: ResponseOutparam) {
stream_file(req, res).await.unwrap();
}
async fn stream_file(_req: IncomingRequest, res: ResponseOutparam) -> Result<()> {
async fn handler(req: IncomingRequest, res: ResponseOutparam) {
if let Err(e) = stream_file(req, res).await {
let response = e.into_response();
// TODO: set response into out param
}
}
async fn stream_file(_req: IncomingRequest, res: ResponseOutparam) -> Result<(), impl IntoResponse> {

We could do the above. We don't have a great way to take an http::Response<Vec<u8>> and set it in the ResponseOutparam but we can add that. I think that would make this much nicer.

Signed-off-by: Radu Matei <radu@fermyon.com>
@rylev
Copy link
Collaborator

rylev commented Oct 25, 2023

Approved this but I do want us to come up with a better way to handle errors other than unwrapping.

@radu-matei radu-matei merged commit b40ef35 into fermyon:main Oct 26, 2023
9 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants