Skip to content

Commit

Permalink
v5.10 - serve_file method
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Oct 19, 2022
1 parent 2b82393 commit 900a0ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <[email protected]>"]
version = "5.9.1"
version = "5.10.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
13 changes: 12 additions & 1 deletion src/Router.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Genie

include("mimetypes.jl")

export route, routes, channel, channels, download, serve_static_file
export route, routes, channel, channels, download, serve_static_file, serve_file
export GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
export tolink, linkto, responsetype, toroute
export params, query, post, headers, request, params!
Expand Down Expand Up @@ -1160,6 +1160,17 @@ function serve_static_file(resource::String; root = Genie.config.server_document
end


function serve_file(f::String) :: HTTP.Response
fileheader = file_headers(f)
if isfile(f)
return HTTP.Response(200, fileheader, body = read(f, String))
else
@error "404 Not Found $f [$(abspath(f))]"
error(f, response_mime(), Val(404))
end
end



"""
download(filepath::String; root) :: HTTP.Response
Expand Down

2 comments on commit 900a0ed

@essenciary
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/70621

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.10.0 -m "<description of version>" 900a0ed4523ff7eafaed24438069069e8824013d
git push origin v5.10.0

Please sign in to comment.