Skip to content

Commit

Permalink
rename and test to_ipaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Vertechi committed Mar 23, 2019
1 parent c4fff90 commit e7f55b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/HTTP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ function ServerWS(h::Function, w::Function; kwargs...)
ServerWS(RequestHandlerFunction(h), WSHandlerFunction(w); kwargs...)
end

to_IPAddr(ip::IPAddr) = ip
to_IPAddr(s::AbstractString) = parse(IPAddr, s)
to_ipaddr(ip::IPAddr) = ip
to_ipaddr(s::AbstractString) = parse(IPAddr, s)

"""
WebSockets.serve(server::ServerWS, port)
Expand All @@ -350,7 +350,7 @@ After a suspected connection task failure:
"""
function serve(serverws::ServerWS, host, port, verbose)
# An internal reference used for closing.
tcpserver = Ref{Union{IOServer, Nothing}}(Sockets.listen(InetAddr(to_IPAddr(host), port)))
tcpserver = Ref{Union{IOServer, Nothing}}(Sockets.listen(InetAddr(to_ipaddr(host), port)))
# Start a couroutine that sleeps until something is put on the .in channel.
@async begin
# Next line will hold until something is put on the channel
Expand Down
9 changes: 8 additions & 1 deletion test/client_serverWS_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ end
@info "External server http request"
@test 200 == WebSockets.HTTP.request("GET", EXTERNALHTTP).status

@info "String to IPAddr conversion"
let
ip = parse(IPAddr, SURL)
@test WebSockets.to_ipaddr(SURL) == WebSockets.to_ipaddr(ip) == ip
end

@info "ServerWS: Open, http response, close. Repeat three times. Takes a while."
for i = 1:3
let
server = startserver()
ip = parse(IPAddr, SURL)
server = startserver(url=ip)
@test 200 == WebSockets.HTTP.request("GET", "http://$SURL:$PORT").status
close(server)
end
Expand Down

0 comments on commit e7f55b9

Please sign in to comment.