diode 1.1 → 1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3614e7e7f1363243b35dd50842fb1c1ebf453517cff842872975867757271169
4
- data.tar.gz: 3524eaa3b323bc16f2d74aeeea0dcd97b24a4d52f0b09b02835a488068ef85a5
3
+ metadata.gz: a78f492d045a8ed2000597384b5bb4ccd16028be81a2e058f18d06be800e2255
4
+ data.tar.gz: 4e8d5ba6375511e05888424c042001622a00ccf9fe2fd268a48fc24ec2edbe56
5
5
  SHA512:
6
- metadata.gz: 3c1b87ca3366315091928fb240e4e511615f6f790821283a09c3d18b2f058ee2de8ec2c3d3166372d1d4c543577eedfaf73057467915920ae444d40a79b4fbaa
7
- data.tar.gz: 6120087c4cc5d244e7deaddc24d3d16537c3891036e2a3887bad470acd282de09472310d67f3f3f511d4bbf535a1f206d3974308b1d3d615ad8abcf3502714b3
6
+ metadata.gz: 9d1b3c20467382e7e3dfbdc7727f0ac7ca351d89cf023777d1cb5af3681dc1570f84230360e910ef36215e2ec7ff24171482eaa7fbdc87f7f4ddc4f4210efd31
7
+ data.tar.gz: 75b9a046bd2dbe1270e32435376d4a591ac7e3a586785bf773a85ac2175836a5f6728bba623ad8e8df13e9798a5e25c0d77fc0592a603b743d2cc6d145f75da8
data/lib/diode/server.rb CHANGED
@@ -3,6 +3,7 @@ require 'time'
3
3
  require 'json'
4
4
  require 'diode/request'
5
5
  require 'diode/response'
6
+ require 'diode/static'
6
7
 
7
8
  module Diode
8
9
 
data/lib/diode/static.rb CHANGED
@@ -8,52 +8,53 @@ class Static
8
8
  end
9
9
 
10
10
  def serve(request)
11
- return Diode::Response.new(405, "Method not allowed", {"Content-type" => "text/plain"}) unless request.method == "GET"
12
- path = Pathname.new(request.path).cleanpath.sub(request.pattern, "") # remove the leading portion matching the mount pattern
13
- filepath = Pathname.new(File.expand_path(path, @root))
14
- return Diode::Response.new(404, "<html><body>File not found</body></html>", {"Content-type" => "text/html"}) unless filepath.exist?
15
- mimetype = @@mimetypes[filepath.extname[1..-1]] || "application/octet-stream"
16
- return Diode::Response.new(200, IO.read(filepath.to_s).b, {"Content-Type"=>mimetype, "Cache-Control" => "no-cache"})
11
+ return Diode::Response.new(405, "Method not allowed", {"Content-type" => "text/plain"}) unless request.method == "GET"
12
+ path = Pathname.new(request.path).cleanpath.sub(request.pattern, "") # remove the leading portion matching the mount pattern
13
+ filepath = Pathname.new(File.expand_path(path, @root))
14
+ filepath = Pathname.new(File.expand_path("index.html", filepath)) if filepath.directory?
15
+ return Diode::Response.new(404, "<html><body>File not found</body></html>", {"Content-type" => "text/html"}) unless filepath.exist?
16
+ mimetype = @@mimetypes[filepath.extname[1..-1]] || "application/octet-stream"
17
+ return Diode::Response.new(200, IO.read(filepath.to_s).b, {"Content-Type"=>mimetype, "Cache-Control" => "no-cache"})
17
18
  end
18
19
 
19
- @@mimetypes = {
20
- "avi" => "video/x-msvideo",
21
- "avif" => "image/avif",
22
- "css" => "text/css",
23
- "gif" => "image/gif",
24
- "htm" => "text/html",
25
- "html" => "text/html",
26
- "ico" => "image/x-icon",
27
- "jpeg" => "image/jpeg",
28
- "jpg" => "image/jpeg",
29
- "js" => "application/javascript",
30
- "json" => "application/json",
31
- "mov" => "video/quicktime",
32
- "mp4" => "video/mp4",
33
- "mpe" => "video/mpeg",
34
- "mpeg" => "video/mpeg",
35
- "mpg" => "video/mpeg",
36
- "otf" => "font/otf",
37
- "pdf" => "application/pdf",
38
- "png" => "image/png",
39
- "qt" => "video/quicktime",
40
- "rb" => "text/plain",
41
- "svg" => "image/svg+xml",
42
- "tif" => "image/tiff",
43
- "tiff" => "image/tiff",
44
- "ttc" => "font/collection",
45
- "ttf" => "font/ttf",
46
- "txt" => "text/plain",
47
- "webm" => "video/webm",
48
- "webp" => "image/webp",
49
- "woff" => "font/woff",
50
- "woff2" => "font/woff2",
51
- "xhtml" => "text/html",
52
- "xml" => "text/xml",
53
- }
20
+ @@mimetypes = {
21
+ "avi" => "video/x-msvideo",
22
+ "avif" => "image/avif",
23
+ "css" => "text/css",
24
+ "gif" => "image/gif",
25
+ "htm" => "text/html",
26
+ "html" => "text/html",
27
+ "ico" => "image/x-icon",
28
+ "jpeg" => "image/jpeg",
29
+ "jpg" => "image/jpeg",
30
+ "js" => "application/javascript",
31
+ "json" => "application/json",
32
+ "mov" => "video/quicktime",
33
+ "mp4" => "video/mp4",
34
+ "mpe" => "video/mpeg",
35
+ "mpeg" => "video/mpeg",
36
+ "mpg" => "video/mpeg",
37
+ "otf" => "font/otf",
38
+ "pdf" => "application/pdf",
39
+ "png" => "image/png",
40
+ "qt" => "video/quicktime",
41
+ "rb" => "text/plain",
42
+ "svg" => "image/svg+xml",
43
+ "tif" => "image/tiff",
44
+ "tiff" => "image/tiff",
45
+ "ttc" => "font/collection",
46
+ "ttf" => "font/ttf",
47
+ "txt" => "text/plain",
48
+ "webm" => "video/webm",
49
+ "webp" => "image/webp",
50
+ "woff" => "font/woff",
51
+ "woff2" => "font/woff2",
52
+ "xhtml" => "text/html",
53
+ "xml" => "text/xml",
54
+ }
54
55
 
55
- def self.mimetypes
56
- @@mimetypes
57
- end
56
+ def self.mimetypes
57
+ @@mimetypes
58
+ end
58
59
 
59
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diode
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kjell Koda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-22 00:00:00.000000000 Z
11
+ date: 2023-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json