From bdca94d1bb45685d5669535023c90515e7327e63 Mon Sep 17 00:00:00 2001 From: nixo Date: Sun, 25 Oct 2020 00:01:31 +0200 Subject: [PATCH] client: init simple get client feature --- src/Gemenon.jl | 1 + src/client.jl | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/client.jl diff --git a/src/Gemenon.jl b/src/Gemenon.jl index 76c0e89..81c7831 100644 --- a/src/Gemenon.jl +++ b/src/Gemenon.jl @@ -7,6 +7,7 @@ export Connection, Request, Status, Response include("types.jl") include("server.jl") +include("client.jl") include("rw.jl") export link, document, status, not_found diff --git a/src/client.jl b/src/client.jl new file mode 100644 index 0000000..213ab8d --- /dev/null +++ b/src/client.jl @@ -0,0 +1,36 @@ +import Base.get +function get(request::Request) + ctx = OpenSSL.SSLContext(mode = OpenSSL.ClientMode) + io = Sockets.connect(request.host, request.port) + + client = SSLClient(ctx, io) + isreadable(io) + + status = OpenSSL.do_ssl_handshake(client) + + while true + if isreadable(io) && length(client.write_buf) == 0 + # verbose && println("do_read") + if OpenSSL.do_sock_read(client) == -1 + break + end + end + if iswritable(io) && length(client.write_buf) > 0 + # verbose && println("do_write") + if OpenSSL.do_sock_write(client) == -1 + break + end + end + # verbose && println("end loop") + if OpenSSL.ssl_init_finished(client) + write(client, string(request, "\r\n")) + while isopen(io) + # println("HERE") + OpenSSL.do_sock_read(client) + end + return String(client.context.data) + end + end +end + +