make the gemini server more generic
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
cd8a9a1168
commit
d5dfe68ad6
37
gemini.moon
37
gemini.moon
|
@ -1,17 +1,5 @@
|
|||
cqueues = require "cqueues"
|
||||
socket = require "cqueues.socket"
|
||||
ln = require "ln"
|
||||
url = require "net.url"
|
||||
|
||||
srv = socket.listen "127.0.0.1", "58816"
|
||||
|
||||
cq = cqueues.new!
|
||||
|
||||
class ProxyRequestRefusedHandler
|
||||
run: (ctx, conn) =>
|
||||
conn\write "53 Proxy request refused \r\n"
|
||||
ln.log ctx, {status: 53}
|
||||
|
||||
class Server
|
||||
new: (cq, hdlr) =>
|
||||
@cq = cq
|
||||
|
@ -30,26 +18,9 @@ class Server
|
|||
host: u.host
|
||||
path: u.path
|
||||
query: u.query
|
||||
@hdlr\run ctx, conn
|
||||
@hdlr\serve ctx, conn
|
||||
\close!
|
||||
|
||||
-- cq\wrap ->
|
||||
-- for conn in srv\clients!
|
||||
-- cq\wrap ->
|
||||
-- with conn
|
||||
-- _, ip = \peername!
|
||||
-- request = \read "*l"
|
||||
-- u = url.parse request
|
||||
-- ctx =
|
||||
-- :ip
|
||||
-- host: u.host
|
||||
-- path: u.path
|
||||
-- query: u.query
|
||||
-- ln.log ctx
|
||||
-- \write "53 Proxy request refused\r\n"
|
||||
-- \close!
|
||||
|
||||
with Server cq, ProxyRequestRefusedHandler!
|
||||
\listen srv
|
||||
|
||||
assert cq\loop!
|
||||
{
|
||||
:Server
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
cqueues = require "cqueues"
|
||||
socket = require "cqueues.socket"
|
||||
ln = require "ln"
|
||||
|
||||
gemini = require "gemini"
|
||||
|
||||
cq = cqueues.new!
|
||||
|
||||
class ProxyRequestRefusedHandler
|
||||
serve: (ctx, conn) =>
|
||||
conn\write "53 Proxy request refused \r\n"
|
||||
ln.log ctx, {status: 53}
|
||||
|
||||
with gemini.Server cq, ProxyRequestRefusedHandler!
|
||||
\listen socket.listen "127.0.0.1", "58816"
|
||||
\listen socket.listen
|
||||
path: "./var/mipha.sock"
|
||||
unlink: true
|
||||
|
||||
assert cq\loop!
|
Loading…
Reference in New Issue