Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow IPAddr in serve #145

Merged
merged 3 commits into from
Mar 23, 2019
Merged

allow IPAddr in serve #145

merged 3 commits into from
Mar 23, 2019

Conversation

piever
Copy link
Contributor

@piever piever commented Mar 22, 2019

Mux uses this code and passes the IP address directly (say localhost = ip"0.0.0.0"::IPAddr). In this way serve supports both passing the string and passing the IPAddr object.

@coveralls
Copy link

coveralls commented Mar 22, 2019

Coverage Status

Coverage increased (+0.03%) to 94.041% when pulling e7f55b9 on piever:pv/ip into 187ebe9 on JuliaWeb:master.

@hustf
Copy link
Collaborator

hustf commented Mar 22, 2019

Do you see other similar needs at this point? Will probably merge and release tomorrow morning if not, after another look.

@piever
Copy link
Contributor Author

piever commented Mar 22, 2019

Thanks, a release would be great. As far as I can see, this was the only thing that needed fixing on the WebSockets side.

@@ -347,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(parse(IPAddr, host), port)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if

IPv4(host::IPv4) 

existed in Sockets, just like

Int(i::Int) 

exists. But it doesn't, just like ServerWS(s::ServerWS) doesn't exist.

src/HTTP.jl Outdated
@@ -322,6 +322,9 @@ function ServerWS(h::Function, w::Function; kwargs...)
ServerWS(RequestHandlerFunction(h), WSHandlerFunction(w); kwargs...)
end

to_IPAddr(ip::IPAddr) = ip
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is good style, considering. Alternatively, we could add

   IPv4(i::IPv4) = ip

but risk that Sockets add a method like that later, and we'd end up with warnings. What do you think?

We need a test for this. But there's also other new methods that are not posted. Will have a look at current test coverage and probably submit a PR to get back up to ~100% coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've followed HTTP convention (which is in line with Julia Base) to lowercase IPAddr in a function name (so now it's to_ipaddr) and have added tests for it. Adding a IPv4(::IPv4) method here would be type piracy: something like that should be added in the Sockets stdlib directly.

@piever
Copy link
Contributor Author

piever commented Mar 23, 2019

I've added tests and addressed the feedback, I think this should be good to merge.

@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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure that we test serving from a IPAddr at least once in the test suite.

@hustf hustf merged commit b160e60 into JuliaWeb:master Mar 23, 2019
@hustf
Copy link
Collaborator

hustf commented Mar 23, 2019

Absolutely magnificent! One less for issue #147.

@piever piever deleted the pv/ip branch March 23, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants