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

Feature: serve_file #567

Open
chris-b1 opened this issue Aug 10, 2020 · 4 comments
Open

Feature: serve_file #567

chris-b1 opened this issue Aug 10, 2020 · 4 comments
Labels
Milestone

Comments

@chris-b1
Copy link
Contributor

chris-b1 commented Aug 10, 2020

This seems like generic enough functionality it could make sense to put in HTTP.jl. I don't have an api figured out, but just as a placeholder/starting point

# ?serve_file
#     serve_file(path; mimetype="infer", extension="infer", ...) :: HTTP.Response
#     serve_file(stream::HTTP.Stream, ...) :: Nothing

using HTTP

function handle_file(req::HTTP.Request)
    return HTTP.serve_file("file.txt") 
end

Some pointers to other implementations

PkgServer - https://github.com/JuliaPackaging/PkgServer.jl/blob/065235d39b4f66018dbc51ce3cb6861429f095e2/src/resource.jl#L394

Genie - https://github.com/GenieFramework/Genie.jl/blob/899ea32d3a7a95aab3bfe508fc9d6821bde2a1e0/src/Router.jl#L992

Flask - https://github.com/pallets/flask/blob/632f85b65354ad573bb33c54a0a9dd3ffcef371f/src/flask/helpers.py#L447

@quinnj
Copy link
Member

quinnj commented Aug 11, 2020

Yeah, I've thought this would be a useful "default" handler to have in place; I'd be in favor

@clarkevans
Copy link
Contributor

See #653

@fonsp
Copy link
Member

fonsp commented Mar 16, 2022

See also #658 , serving a file can be a bigger project than it sounds, and it might benefit from being separated from HTTP.jl, or perhaps as part of a router package. A good file server should set the right cache & mime headers, support ranged requests, HEAD requests, and more.

@fonsp fonsp added the server About our HTTP server label Mar 16, 2022
@quinnj
Copy link
Member

quinnj commented May 27, 2022

There's a solid implementation that go includes in their stdlib here. If someone wanted to take a stab at translating to Julia, I think it would be fairly straightforward. I'm not going to mark this as 1.0 as it's an easy add-on post 1.0. If someone is interested, just comment here and I'll assign it; otherwise I'll get to this eventually in the future.

@quinnj quinnj added this to the 1.X milestone May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants