client: Better request handling, client certificates support

This commit is contained in:
nixo 2020-10-25 10:42:49 +01:00
parent c839dee6ea
commit ee847f0f04
1 changed files with 15 additions and 8 deletions

View File

@ -1,13 +1,22 @@
import Base.get
function get(request::Request)
function get(request::Request; certs::Union{CAChain,Nothing} = nothing)
req = string(request)
let len = sizeof(req)
if len > 1024
throw(OverflowError(
"Maximum <URL> size is 1024 bytes (yours is $len)!"))
end
end
data = string(req, "\r\n")
ctx = OpenSSL.SSLContext(mode = OpenSSL.ClientMode)
# Use certificates, if provided
isnothing(certs) || Gemenon.OpenSSL.ca_chain!(ctx, certs.cert, certs.key)
io = Sockets.connect(request.host, request.port)
client = SSLClient(ctx, io)
isreadable(io)
status = OpenSSL.do_ssl_handshake(client)
OpenSSL.do_ssl_handshake(client)
while true
if isreadable(io) && length(client.write_buf) == 0
# verbose && println("do_read")
@ -23,7 +32,7 @@ function get(request::Request)
end
# verbose && println("end loop")
if OpenSSL.ssl_init_finished(client)
write(client, string(request, "\r\n"))
write(client, data)
while isopen(io)
# println("HERE")
OpenSSL.do_sock_read(client)
@ -32,5 +41,3 @@ function get(request::Request)
end
end
end