Skip to content

Commit

Permalink
fixing mime types and trailing backslashes
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Mar 15, 2022
1 parent b70a32b commit 91e9e9e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LiveServer"
uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589"
authors = ["Jonas Asprion <[email protected]", "Thibaut Lienart <[email protected]>"]
version = "0.7.3"
version = "0.7.4"

[deps]
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down
14 changes: 7 additions & 7 deletions src/mimetypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const MIME_TYPES = Dict{String,String}([
("cmx", "image/x-cmx"),
("cod", "application/vnd.rim.cod"),
("com", "application/x-msdownload"),
("conf", "text/plain"),
("conf", "text/plain; charset=utf-8"),
("cpio", "application/x-cpio"),
("cpp", "text/x-c"),
("cpt", "application/mac-compactpro"),
Expand Down Expand Up @@ -177,7 +177,7 @@ const MIME_TYPES = Dict{String,String}([
("dd2", "application/vnd.oma.dd2+xml"),
("ddd", "application/vnd.fujixerox.ddd"),
("deb", "application/x-debian-package"),
("def", "text/plain"),
("def", "text/plain; charset=utf-8"),
("deploy", "application/octet-stream"),
("der", "application/x-x509-ca-cert"),
("dfac", "application/vnd.dreamfactory"),
Expand Down Expand Up @@ -354,7 +354,7 @@ const MIME_TYPES = Dict{String,String}([
("iif", "application/vnd.shana.informed.interchange"),
("imp", "application/vnd.accpac.simply.imp"),
("ims", "application/vnd.ms-ims"),
("in", "text/plain"),
("in", "text/plain; charset=utf-8"),
("ink", "application/inkml+xml"),
("inkml", "application/inkml+xml"),
("install", "application/x-install-instructions"),
Expand Down Expand Up @@ -409,11 +409,11 @@ const MIME_TYPES = Dict{String,String}([
("les", "application/vnd.hhe.lesson-player"),
("lha", "application/x-lzh-compressed"),
("link66", "application/vnd.route66.link66+xml"),
("list", "text/plain"),
("list", "text/plain; charset=utf-8"),
("list3820", "application/vnd.ibm.modcap"),
("listafp", "application/vnd.ibm.modcap"),
("lnk", "application/x-ms-shortcut"),
("log", "text/plain"),
("log", "text/plain; charset=utf-8"),
("lostxml", "application/lost+xml"),
("lrf", "application/octet-stream"),
("lrm", "application/vnd.ms-lrm"),
Expand Down Expand Up @@ -807,7 +807,7 @@ const MIME_TYPES = Dict{String,String}([
("tex", "application/x-tex"),
("texi", "application/x-texinfo"),
("texinfo", "application/x-texinfo"),
("text", "text/plain"),
("text", "text/plain; charset=utf-8"),
("tfi", "application/thraud+xml"),
("tfm", "application/x-tex-tfm"),
("tga", "image/x-tga"),
Expand All @@ -830,7 +830,7 @@ const MIME_TYPES = Dict{String,String}([
("twds", "application/vnd.simtech-mindmapper"),
("txd", "application/vnd.genomatix.tuxedo"),
("txf", "application/vnd.mobius.txf"),
("txt", "text/plain"),
("txt", "text/plain; charset=utf-8"),
("u32", "application/x-authorware-bin"),
("udeb", "application/x-debian-package"),
("ufd", "application/vnd.ufdl"),
Expand Down
19 changes: 10 additions & 9 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ function get_fs_path(req_path::AbstractString)::String
fs_path = joinpath(CONTENT_DIR[], fs_path)
end

# if it ends with `/` try to see if there's an index.html
if endswith(uri.path, '/')
tmp = joinpath(fs_path, "index.html")
isfile(tmp) && return tmp
end
# otherwise return the path if it exists (file or dir)
(isfile(fs_path) || isdir(fs_path)) && return fs_path
# otherwise --> this will lead to a 404
isfile(fs_path) && return fs_path

tmp = joinpath(fs_path, "index.html")
isfile(tmp) && return tmp

# content of the dir will be shown
isdir(fs_path) && return fs_path

# 404 will be shown
return ""
end

Expand Down Expand Up @@ -266,7 +267,7 @@ function serve_file(

# build the response with appropriate mime type (this is inspired from Mux
# https://github.com/JuliaWeb/Mux.jl/blob/master/src/examples/files.jl)
mime = get(MIME_TYPES, ext, "text/plain")
mime = get(MIME_TYPES, ext, HTTP.sniff(content))

# if html-like, try adding the browser-sync script to it
inject_reload = inject_browser_reload_script &&
Expand Down

2 comments on commit 91e9e9e

@tlienart
Copy link
Collaborator 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/56630

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 v0.7.4 -m "<description of version>" 91e9e9ead216bb08c5a5bf9e85e555f1b5f0f641
git push origin v0.7.4

Please sign in to comment.