diamant 0.0.1 → 0.0.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/diamant.rb +29 -8
- data/lib/diamant/mimetype.rb +5 -8
- data/lib/diamant/version.rb +1 -1
- 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: 72a20983fb5689076b1da91f753515fb251f96c73917628ba5d2e975d34c526c
|
4
|
+
data.tar.gz: efed078e4f3f0f2a556da98b2308fdc2d6d2af927b4e7ef61901b08490e4ef55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c15a92708e8b9bf8ebc746dd850e4f500affbac1fe32e29c0ee2b73efd998b12865ba2e6f68dd130bf42f3f042eed267852ed9a545bcc15797264ccbd39edc3f
|
7
|
+
data.tar.gz: '084cca645aa707d1140a787a35a8a548a2385bb9dfc4aa25110df0f8b75875238595accf4feb21bcc4f7cc9ec5d5e431ec75ace67943f0d48d3abae14f8674c7'
|
data/lib/diamant.rb
CHANGED
@@ -39,20 +39,41 @@ module Diamant
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
def reject_request?(sock, current_load)
|
43
|
+
# Accept only 10 thread with no restriction
|
44
|
+
return false if current_load < 11
|
45
|
+
# Seppuku
|
46
|
+
raise 'Server is under heavy load' if current_load > 1965
|
47
|
+
if current_load > 42
|
48
|
+
@logger.warn '41 - Too much threads...'
|
49
|
+
sock.puts "41 See you soon...\r\n"
|
50
|
+
return true
|
48
51
|
end
|
49
|
-
|
50
|
-
@logger.
|
52
|
+
# Please wait a little
|
53
|
+
@logger.warn '44 5 - Too much threads...'
|
54
|
+
sock.puts "44 5\r\n"
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
def handle_client(client)
|
59
|
+
current_load = Thread.list.length - 1
|
60
|
+
return if reject_request?(client, current_load)
|
61
|
+
uri, answer = read_file(client)
|
62
|
+
log_line = [current_load, client.peeraddr[3], answer[0]]
|
63
|
+
log_line << uri if uri
|
64
|
+
@logger.info log_line.join(' - ')
|
51
65
|
answer.each do |line|
|
52
66
|
client.puts "#{line}\r\n"
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
70
|
+
def read_file(client)
|
71
|
+
r = Net::GeminiRequest.read_new(client)
|
72
|
+
[r.uri, route(r.path)]
|
73
|
+
rescue Net::GeminiBadRequest
|
74
|
+
[nil, ["59\r\n"]]
|
75
|
+
end
|
76
|
+
|
56
77
|
def build_response(route)
|
57
78
|
info = Diamant::MimeType.new(route)
|
58
79
|
answer = IO.readlines route, chomp: true
|
data/lib/diamant/mimetype.rb
CHANGED
@@ -8,10 +8,12 @@ module Diamant
|
|
8
8
|
attr_reader :extension, :content_type
|
9
9
|
|
10
10
|
MIMETYPES = {
|
11
|
+
'.gemini' => 'text/gemini',
|
11
12
|
'.gmi' => 'text/gemini',
|
12
13
|
'.txt' => 'text/plain',
|
13
14
|
'.md' => 'text/markdown',
|
14
15
|
'.org' => 'text/org',
|
16
|
+
'.xml' => 'application/xml',
|
15
17
|
'.png' => 'image/png',
|
16
18
|
'.jpg' => 'image/jpeg',
|
17
19
|
'.jpeg' => 'image/jpeg',
|
@@ -24,7 +26,7 @@ module Diamant
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def supported?
|
27
|
-
@extension
|
29
|
+
@extension != '' && MIMETYPES.has_key?(@extension)
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
@@ -32,13 +34,8 @@ module Diamant
|
|
32
34
|
def extract_info
|
33
35
|
@extension = File.extname @path
|
34
36
|
raise MimeError, "#{@path} format is not supported!" unless supported?
|
35
|
-
|
36
|
-
|
37
|
-
@content_type = 'text/plain'
|
38
|
-
else
|
39
|
-
# Any other supported extension
|
40
|
-
@content_type = MIMETYPES[@extension]
|
41
|
-
end
|
37
|
+
# Any other supported extension
|
38
|
+
@content_type = MIMETYPES[@extension]
|
42
39
|
end
|
43
40
|
end
|
44
41
|
end
|
data/lib/diamant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diamant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Étienne Deparis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-net-text
|