client: init simple get client feature
This commit is contained in:
parent
1dc60fd103
commit
bdca94d1bb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue