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

Serving either JSON string or static file (hyper 1.0+) #47

Open
eldenpark opened this issue Feb 14, 2024 · 1 comment
Open

Serving either JSON string or static file (hyper 1.0+) #47

eldenpark opened this issue Feb 14, 2024 · 1 comment

Comments

@eldenpark
Copy link

Previously with hyper 0.14, I was able to design a server with hyper and hyper-staticfile (0.9.x) to serve different types of requests, depending on the URI that requests plain JSON string or the others for static files.

Now with the new version of hyper-staticfile w/ hyper 1.0+, it became a bit more difficult. Body enum seems to have Empty or Stream variants so this by default can't handle { "foo": "1" } type of response. Any idea where I should work to make this ideally work?

@stephank
Copy link
Owner

I think Response::map might work for you? https://docs.rs/http/1.0.0/http/response/struct.Response.html#method.map

Alternatively, you can do into_parts + from_parts: https://docs.rs/http/1.0.0/http/response/struct.Response.html#method.from_parts

Both should allow you to create a new Response with a different body type, while preserving all the headers, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants