diode 1.3.1 → 1.3.3

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: b48c0ef0d062a22a1a859065f2320cda02d13c861cc2dc96d5a0f6a44d070a56
4
- data.tar.gz: 6dba85d23da905543b0f2518c6a18ff7c31dce8741c6ca6126d92bc52719a239
3
+ metadata.gz: 1a336c0eda5cf34b05fe4d4fe013dc181af28163588ede63ba741c76c8e976b9
4
+ data.tar.gz: e84ea6a14a4b6a8682e0ce74593c23fe828bf36ac19d5072b5a534a4c44eb632
5
5
  SHA512:
6
- metadata.gz: '09facf23abbab77b23158dae5b70d66c4d3c58c2c67d82511f9fb10c4cf1e123836d5d767e5a3152e813b7ae75d0388fd63b8f0ab9b4a4317c78d0acfa8729ed'
7
- data.tar.gz: 70ebbbdea54c6dd15dcfe8af2234f1dd5a3364f6098c40be7ad33fa5ead7d31517557a07246acb65538dbaf8aa0bdf4680474e9078394611a51510855c4ea73c
6
+ metadata.gz: c86e2f8c48f2c053f4f236113de844f811b42058f9d62895cb00b1db397c22ec221bc577366674a35ecc9c463ab8296c378871f8d7ea280427930035eeb2c056
7
+ data.tar.gz: b31be1338d45b4999c3688778aacdc7946140444a0293f30cf0c986a3747fd7105e59f687ca782c98e2b79595faa12f3c03bd436a84e74828266d98942f97548
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
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.new(405, "Method not allowed", {"Content-type" => "text/plain"}) unless request.method == "GET"
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
14
23
  path = Pathname.new(request.path).cleanpath().to_s()
15
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.new(404, "<html><body>File not found</body></html>", {"Content-type" => "text/html"}) unless filepath.exist?
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.1
4
+ version: 1.3.3
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-19 00:00:00.000000000 Z
11
+ date: 2024-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json