JuliaWeb/HTTP.jl

Feature: serve_file

Open

#567 opened on Aug 10, 2020

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Julia (679 stars) (182 forks)batch import
enhancementhelp wantedserver

Description

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

Contributor guide