diode 1.3.0 → 1.3.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 +4 -4
- data/lib/diode/request.rb +6 -2
- data/lib/diode/server.rb +1 -0
- data/lib/diode/static.rb +14 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea33eabe22d4cdc90c861901276c3c1f9f397d631c3aba3b9a541f1f87390189
|
4
|
+
data.tar.gz: 3d5616c2b0a342f229b49a3e7c27c77c4c255484c21876f2cdfadf7cbe7a4ffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ccade8f6c924359da6ebe142220351b5462015bfee482399cd7e52fb09ef2349df610c6d2e149d9128a4f76af0fc56c8c14b1fcc1dc44337d456379c333b903
|
7
|
+
data.tar.gz: 31869f03329647cac6f4a5d7746d1801683105b538b5c98cfdb3bad0643153b39044f7611de323b84061e503b4f4ee2baacd959100821d5086fd181da318cec9
|
data/lib/diode/request.rb
CHANGED
@@ -14,6 +14,9 @@ class RequestError < StandardError
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class SecurityError < StandardError
|
17
|
+
def code()
|
18
|
+
403
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
class Request
|
@@ -50,11 +53,12 @@ class Request
|
|
50
53
|
headerline, sep, msg = msg.partition("\r\n")
|
51
54
|
while not headerline.strip.empty?
|
52
55
|
key, value = headerline.strip.split(': ')
|
56
|
+
key = key.strip.downcase().split(/\b/).collect{|e| e[0].upcase + e[1..-1].downcase}.join("") # title case
|
57
|
+
raise(Diode::RequestError.new(400, "duplicate header '#{key}'")) if headers.keys.include?(key)
|
53
58
|
@headers[key] = value
|
54
59
|
headerline, sep, msg = msg.partition("\r\n")
|
55
60
|
end
|
56
|
-
rescue EOFError
|
57
|
-
# tolerate missing \r\n at end of request
|
61
|
+
rescue EOFError # tolerate missing \r\n at end of request
|
58
62
|
end
|
59
63
|
@cookies = {}
|
60
64
|
if @headers.key?("Cookie")
|
data/lib/diode/server.rb
CHANGED
@@ -48,6 +48,7 @@ class Server
|
|
48
48
|
# check routing table is sane
|
49
49
|
def validate_routing()
|
50
50
|
newRouting = []
|
51
|
+
raise("routing must be an Array") unless @routing.is_a?(Array)
|
51
52
|
@routing.each { |pattern, klass, *args|
|
52
53
|
raise("invalid pattern='#{pattern}' in routing table") unless pattern.is_a?(Regexp)
|
53
54
|
begin
|
data/lib/diode/static.rb
CHANGED
@@ -4,17 +4,26 @@ module Diode
|
|
4
4
|
|
5
5
|
class Static
|
6
6
|
|
7
|
-
def initialize(docRoot=".")
|
7
|
+
def initialize(docRoot=".", guardian=nil)
|
8
8
|
@root = Pathname.new(Pathname.new(docRoot).cleanpath()).realpath()
|
9
9
|
raise("Cannot serve static files from path #{@root}") unless @root.directory? and @root.readable?
|
10
|
+
@guardian = guardian
|
10
11
|
end
|
11
12
|
|
12
13
|
def serve(request)
|
13
|
-
return Diode::Response.
|
14
|
-
|
15
|
-
|
14
|
+
return Diode::Response.standard(405) unless request.method == "GET"
|
15
|
+
unless guardian.nil?
|
16
|
+
securityResponse = guardian.call(request)
|
17
|
+
unless securityResponse.nil? or securityResponse == 200
|
18
|
+
return securityResponse if securityResponse.is_a?(Diode::Response)
|
19
|
+
return Diode::Response.standard(securityResponse) if [400,403,404,405].include?(securityResponse)
|
20
|
+
raise("result of guardian block must be a Diode::Response or one of 400,403,404,405 to deny or else nil to allow") # guardian should log details
|
21
|
+
end
|
22
|
+
end
|
23
|
+
path = Pathname.new(request.path).cleanpath().to_s()
|
24
|
+
filepath = Pathname.new(File.expand_path(@root.to_s() + path))
|
16
25
|
filepath = Pathname.new(File.expand_path("index.html", filepath)) if filepath.directory?
|
17
|
-
return Diode::Response.
|
26
|
+
return Diode::Response.standard(404) unless filepath.exist?
|
18
27
|
mimetype = @@mimetypes[filepath.extname[1..-1]] || "application/octet-stream"
|
19
28
|
return Diode::Response.new(200, IO.read(filepath.to_s).b, {"Content-Type"=>mimetype, "Cache-Control" => "no-cache"})
|
20
29
|
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.3.
|
4
|
+
version: 1.3.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: 2024-04-
|
11
|
+
date: 2024-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|