Skip to content

Commit b069744

Browse files
committed
small changes
1 parent 2fde71e commit b069744

File tree

10 files changed

+55
-7
lines changed

10 files changed

+55
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LiveServer"
22
uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589"
33
authors = ["Jonas Asprion <jonas.asprion@gmx.ch", "Thibaut Lienart <tlienart@me.com>"]
4-
version = "0.8"
4+
version = "0.8.1"
55

66
[deps]
77
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
44

55
[compat]
6-
Documenter = "^0.24, ^0.25"
6+
Documenter = "^0.27"

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ makedocs(
2525
)
2626

2727
deploydocs(
28-
repo = "github.com/asprionj/LiveServer.jl.git"
28+
repo = "github.com/tlienart/LiveServer.jl.git"
2929
)

src/server.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,11 @@ function serve_file(
257257
return HTTP.Response(200, index_page)
258258
end
259259

260-
#
261260
# In what follows, fs_path points to a file
262261
# --> html-like: try to inject reload-script
263262
# --> other: just get the browser to show it
264263
#
265-
266-
ext = lstrip(last(splitext(fs_path)), '.')
264+
ext = lstrip(last(splitext(fs_path)), '.') |> string
267265
content = read(fs_path, String)
268266

269267
# build the response with appropriate mime type (this is inspired from Mux
@@ -277,9 +275,25 @@ function serve_file(
277275
end
278276
end
279277

278+
# avoid overly-specific text types so the browser can try rendering
279+
# all text-like documents instead of offering to download all files
280+
m = match(r"^text\/(.*?);(.*)$", content_type)
281+
if m !== nothing
282+
text_type = m.captures[1]
283+
if text_type ("html", "javascript", "css")
284+
content_type = "text/plain;$(m.captures[2])"
285+
end
286+
end
287+
plain = "text/plain; charset=utf8"
288+
content_type = replace(
289+
content_type,
290+
"application/toml" => plain,
291+
"application/x-sh" => plain
292+
)
293+
280294
# if html-like, try adding the browser-sync script to it
281295
inject_reload = inject_browser_reload_script && (
282-
startswith(content_type, "text/html") ||
296+
startswith(content_type, "text/html") ||
283297
startswith(content_type, "application/xhtml+xml")
284298
)
285299

@@ -301,6 +315,7 @@ function serve_file(
301315
end
302316

303317
headers = ["Content-Type" => content_type]
318+
304319
if allow_cors
305320
push!(headers, "Access-Control-Allow-Origin" => "*")
306321
end

test/mimes/cpp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
int main()
4+
{
5+
std::cout << "Hello, world!\n";
6+
}

test/mimes/foo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifdef MACRO
2+
3+
controlled text
4+
5+
#endif /* MACRO */

test/mimes/jl.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function foo()
2+
return 0
3+
end

test/mimes/py.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def foo():
2+
return 0

test/mimes/sh.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
for i in 'Alfa Romeo' 'Bentley' 'Citroën'; do
4+
echo $i
5+
done

test/mimes/toml.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Das ist ein TOML-Dokument.
2+
title = "TOML Beispiel"
3+
4+
[person]
5+
name = "Tom Preston-Werner"
6+
geburtstag = 1979-05-27T07:32:00-08:00
7+
8+
[datenbank]
9+
adresse = "192.168.1.1"
10+
ports = [ 8001, 8001, 8002 ]
11+
verbindungen_max = 5000
12+
aktiviert = true # booleans

0 commit comments

Comments
 (0)