Compare commits

...

6 Commits
v0.1 ... master

Author SHA1 Message Date
nixo db423191d9 fixup 2020-11-12 16:32:05 +01:00
nixo 5b5f989f6b allow unescape of nothing 2020-11-12 16:23:50 +01:00
nixo 8d62ce5f29 fix broken example (missing server mode) 2020-11-01 21:09:48 +01:00
nixo d105d81f5c org: add tangle 2020-11-01 21:09:36 +01:00
nixo 7a2e06129d add sni support (requires latest OpenSSL) 2020-11-01 19:20:38 +01:00
nixo e0c52b3c86 readme example: use default port 2020-11-01 19:20:04 +01:00
3 changed files with 11 additions and 6 deletions

View File

@ -11,16 +11,16 @@ It's written in [[https://julialang.org/][Julia]].
The usage is quite simple and similar to [[https://github.com/JuliaWeb/HTTP.jl][HTTP.jl]] The usage is quite simple and similar to [[https://github.com/JuliaWeb/HTTP.jl][HTTP.jl]]
First, import the library First, import the library
#+begin_src julia #+begin_src julia :tangle server.jl
using Gemenon using Gemenon
#+end_src #+end_src
Then, setup the SSL config Then, setup the SSL config
#+begin_src julia #+begin_src julia :tangle server.jl
const verify_callback(preverify_ok, x509_ctx)::Cint = 1 const verify_callback(preverify_ok, x509_ctx)::Cint = 1
function init_ssl_context() function init_ssl_context()
ctx = Gemenon.OpenSSL.SSLContext() ctx = Gemenon.OpenSSL.SSLContext(mode = Gemenon.OpenSSL.ServerMode)
Gemenon.OpenSSL.ca_chain!(ctx, "./cert.crt", "./key.key") Gemenon.OpenSSL.ca_chain!(ctx, "./cert.crt", "./key.key")
Gemenon.OpenSSL.set_options!(ctx, Gemenon.OpenSSL.SSL_OP_NO_SSLv3) Gemenon.OpenSSL.set_options!(ctx, Gemenon.OpenSSL.SSL_OP_NO_SSLv3)
@ -36,7 +36,7 @@ Then, setup the SSL config
You are ready to listen for connections! You are ready to listen for connections!
You can do this like in Mux.jl You can do this like in Mux.jl
#+begin_src julia #+begin_src julia :tangle server.jl
@app test = ( @app test = (
req -> document(req.conn, """ req -> document(req.conn, """
# Welcome to Gemenon! # Welcome to Gemenon!
@ -45,5 +45,5 @@ You can do this like in Mux.jl
=> gemini://nixo.xyz/ The Gemenon-Powered Anonymous Board => gemini://nixo.xyz/ The Gemenon-Powered Anonymous Board
""")) """))
serve(test, init_ssl_context, Gemenon.Sockets.ip"0.0.0.0", 1999) serve(test, init_ssl_context, Gemenon.Sockets.ip"0.0.0.0", 1965)
#+end_src #+end_src

View File

@ -1,5 +1,6 @@
import Base.get import Base.get
function get(request::Request; certs::Union{CAChain,Nothing} = nothing) function get(request::Request; certs::Union{CAChain,Nothing} = nothing,
sni = true)
req = string(request) req = string(request)
let len = sizeof(req) let len = sizeof(req)
if len > 1024 if len > 1024
@ -15,6 +16,8 @@ function get(request::Request; certs::Union{CAChain,Nothing} = nothing)
io = Sockets.connect(request.host, request.port) io = Sockets.connect(request.host, request.port)
client = SSLClient(ctx, io) client = SSLClient(ctx, io)
sni && @show OpenSSL.set_host_name(client, request.host)
OpenSSL.do_ssl_handshake(client) OpenSSL.do_ssl_handshake(client)
while true while true

View File

@ -84,6 +84,8 @@ function Request(protocol, host, port, path, query)
path, query, true, "") path, query, true, "")
end end
unescape(::Nothing) = ""
"unescape(percent_encoded_uri)::String "unescape(percent_encoded_uri)::String
Replace %xx escaped chars with their single-character equivalent. Replace %xx escaped chars with their single-character equivalent.