bgeminiserver 1.0.2 → 1.1.1
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/geminiserver.rb +46 -7
- 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: bd1e280a4c3dcf85d33674f3fc2fbe3c5c6071d9a7c23f17b590bf9b73929aa5
|
4
|
+
data.tar.gz: e83851c3efe97e4c651c58cf906c7be1e3436e7aaa8c1be9ef6dac01ce5d4ee8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b7f6e394db408730b41f058df94ca20ecbdaee43a3c29c0686d68c837b813b1d56f1facc411b8c37114ba6d09410e4ae68b0a3df3bdb17dca0a87fdba2fb1fa
|
7
|
+
data.tar.gz: 21110d66e79b6cf8bebaa8fe07c1fabf06c354114d8bb2a946e95258191cae2d29164e59df8f37a34ae4dfad09bd679e1ba9d5693d6cdac559870d516bfab4e1
|
data/lib/geminiserver.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "socket"
|
3
3
|
require "openssl"
|
4
4
|
require "uri"
|
5
|
+
require "timeout"
|
5
6
|
|
6
7
|
module GeminiPage
|
7
8
|
|
@@ -107,6 +108,24 @@ module GeminiPage
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
111
|
+
class GenericGeminiError < RuntimeError
|
112
|
+
def initialize msg
|
113
|
+
super msg
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class BadRequestGemini < GenericGeminiError
|
118
|
+
def initialize msg
|
119
|
+
super msg
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class ProxyRequestRefusedGemini < GenericGeminiError
|
124
|
+
def initialize msg
|
125
|
+
super msg
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
110
129
|
# @example A test server
|
111
130
|
# cert = OpenSSL::X509::Certificate.new File.read "cert.crt"
|
112
131
|
# key = OpenSSL::PKey::RSA.new File.read "priv.pem"
|
@@ -187,7 +206,7 @@ end
|
|
187
206
|
# serv.listen true
|
188
207
|
class GeminiServer
|
189
208
|
|
190
|
-
attr_accessor :not_found_page
|
209
|
+
attr_accessor :not_found_page, :client_timeout
|
191
210
|
|
192
211
|
# Creates a Gemini Server
|
193
212
|
#
|
@@ -208,6 +227,7 @@ class GeminiServer
|
|
208
227
|
@context.verify_callback = ->(passed, cert) { return true }
|
209
228
|
@handlers = {}
|
210
229
|
@not_found_page = GeminiPage.static_page("51", "Not found")
|
230
|
+
@client_timeout = 10
|
211
231
|
end
|
212
232
|
|
213
233
|
# Starts the server. However, the server does not yet respond to requests.
|
@@ -266,10 +286,24 @@ class GeminiServer
|
|
266
286
|
begin
|
267
287
|
Thread.new(@secure.accept) do |conn|
|
268
288
|
begin
|
269
|
-
|
289
|
+
request_line = Timeout::timeout(@client_timeout) {
|
290
|
+
conn.gets.chomp
|
291
|
+
}
|
270
292
|
|
271
|
-
if
|
272
|
-
|
293
|
+
if request_line == ""
|
294
|
+
raise BadRequestGemini.new "Request line is empty"
|
295
|
+
end
|
296
|
+
|
297
|
+
if request_line.length > 1024
|
298
|
+
raise BadRequestGemini.new "URI is too longs"
|
299
|
+
end
|
300
|
+
|
301
|
+
uri = URI(request_line)
|
302
|
+
|
303
|
+
if uri.scheme == nil
|
304
|
+
raise BadRequestGemini.new "No scheme"
|
305
|
+
elsif uri.scheme != "gemini"
|
306
|
+
raise ProxyRequestRefusedGemini.new "Unknown scheme: #{uri.scheme}"
|
273
307
|
end
|
274
308
|
|
275
309
|
if @handlers[uri.path]
|
@@ -279,11 +313,16 @@ class GeminiServer
|
|
279
313
|
page = @not_found_page.(conn, conn.peer_cert, URI.decode_www_form_component(uri.query.to_s))
|
280
314
|
end
|
281
315
|
|
282
|
-
|
283
|
-
conn.
|
316
|
+
rescue ProxyRequestRefusedGemini
|
317
|
+
conn.print "53 #{$!}"
|
318
|
+
rescue URI::InvalidURIError, BadRequestGemini
|
319
|
+
conn.print "59 #{$!}"
|
320
|
+
rescue Timeout::Error
|
321
|
+
conn.print "40 Timeout"
|
284
322
|
rescue
|
285
323
|
$stderr.puts $!
|
286
324
|
end
|
325
|
+
conn.close
|
287
326
|
end
|
288
327
|
rescue
|
289
328
|
$stderr.puts $!
|
@@ -291,4 +330,4 @@ class GeminiServer
|
|
291
330
|
end
|
292
331
|
end
|
293
332
|
|
294
|
-
end
|
333
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bgeminiserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Kuethe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A small Gemini server, to customize with static and dynamic content.
|
14
14
|
The Gem is documented with example. Before I extended the server, the server was
|