diode 1.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3614e7e7f1363243b35dd50842fb1c1ebf453517cff842872975867757271169
4
- data.tar.gz: 3524eaa3b323bc16f2d74aeeea0dcd97b24a4d52f0b09b02835a488068ef85a5
3
+ metadata.gz: afa0bf0af528f72eb3920cc13af9ee2b5942423eb32475b0d3d406500221d1ce
4
+ data.tar.gz: a908dd25d30fb283c14890cd6a0bcee4ccbb1cbc01bccce1f9e93ca18a611543
5
5
  SHA512:
6
- metadata.gz: 3c1b87ca3366315091928fb240e4e511615f6f790821283a09c3d18b2f058ee2de8ec2c3d3166372d1d4c543577eedfaf73057467915920ae444d40a79b4fbaa
7
- data.tar.gz: 6120087c4cc5d244e7deaddc24d3d16537c3891036e2a3887bad470acd282de09472310d67f3f3f511d4bbf535a1f206d3974308b1d3d615ad8abcf3502714b3
6
+ metadata.gz: 6060689ab753f9f3ea5303a03790b78158e665ea237c1215756dbaeb75ceebe534c2c0b96ce97d960e6e12f7147ab5b7798a770d73bc486d53a3c2d1a56a3bfd
7
+ data.tar.gz: dedaeb80985c8f514a88ce63b786f616d3102e0a5e001b3529a9777d879f7fccde2bd22c3b6bbd7973a30df30343076dada798ea5c6c6a0dac6fd1f66eab2c10
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
@@ -1,5 +1,7 @@
1
1
  require 'pathname'
2
2
 
3
+ module Diode
4
+
3
5
  class Static
4
6
 
5
7
  def initialize(docRoot=".")
@@ -8,52 +10,54 @@ class Static
8
10
  end
9
11
 
10
12
  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"})
13
+ return Diode::Response.new(405, "Method not allowed", {"Content-type" => "text/plain"}) unless request.method == "GET"
14
+ path = Pathname.new(request.path).cleanpath.sub(request.pattern, "") # remove the leading portion matching the mount pattern
15
+ filepath = Pathname.new(File.expand_path(path, @root))
16
+ filepath = Pathname.new(File.expand_path("index.html", filepath)) if filepath.directory?
17
+ return Diode::Response.new(404, "<html><body>File not found</body></html>", {"Content-type" => "text/html"}) unless filepath.exist?
18
+ mimetype = @@mimetypes[filepath.extname[1..-1]] || "application/octet-stream"
19
+ return Diode::Response.new(200, IO.read(filepath.to_s).b, {"Content-Type"=>mimetype, "Cache-Control" => "no-cache"})
17
20
  end
18
21
 
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
- }
22
+ @@mimetypes = {
23
+ "avi" => "video/x-msvideo",
24
+ "avif" => "image/avif",
25
+ "css" => "text/css",
26
+ "gif" => "image/gif",
27
+ "htm" => "text/html",
28
+ "html" => "text/html",
29
+ "ico" => "image/x-icon",
30
+ "jpeg" => "image/jpeg",
31
+ "jpg" => "image/jpeg",
32
+ "js" => "application/javascript",
33
+ "json" => "application/json",
34
+ "mov" => "video/quicktime",
35
+ "mp4" => "video/mp4",
36
+ "mpe" => "video/mpeg",
37
+ "mpeg" => "video/mpeg",
38
+ "mpg" => "video/mpeg",
39
+ "otf" => "font/otf",
40
+ "pdf" => "application/pdf",
41
+ "png" => "image/png",
42
+ "qt" => "video/quicktime",
43
+ "rb" => "text/plain",
44
+ "svg" => "image/svg+xml",
45
+ "tif" => "image/tiff",
46
+ "tiff" => "image/tiff",
47
+ "ttc" => "font/collection",
48
+ "ttf" => "font/ttf",
49
+ "txt" => "text/plain",
50
+ "webm" => "video/webm",
51
+ "webp" => "image/webp",
52
+ "woff" => "font/woff",
53
+ "woff2" => "font/woff2",
54
+ "xhtml" => "text/html",
55
+ "xml" => "text/xml",
56
+ }
54
57
 
55
- def self.mimetypes
56
- @@mimetypes
57
- end
58
+ def self.mimetypes
59
+ @@mimetypes
60
+ end
58
61
 
59
62
  end
63
+ 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.1
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-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json