Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/http/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require "./common"
# context.response.print "Hello world!"
# end
#
# server.bind 8080
# server.bind_tcp 8080
# puts "Listening on http://127.0.0.1:8080"
# server.listen
# ```
Expand All @@ -53,7 +53,7 @@ require "./common"
# context.response.print "Hello world!"
# end
#
# server.bind "0.0.0.0", 8080
# server.bind_tcp "0.0.0.0", 8080
# puts "Listening on http://0.0.0.0:8080"
# server.listen
# ```
Expand All @@ -72,7 +72,7 @@ require "./common"
# HTTP::StaticFileHandler.new("."),
# ])
#
# server.bind "127.0.0.1", 8080
# server.bind_tcp "127.0.0.1", 8080
# server.listen
# ```
#
Expand All @@ -91,7 +91,7 @@ require "./common"
# context.response.print "Hello world!"
# end
#
# server.bind "0.0.0.0", 8080
# server.bind_tcp "0.0.0.0", 8080
# server.listen
# ```
class HTTP::Server
Expand Down Expand Up @@ -131,6 +131,11 @@ class HTTP::Server
# Creates a `TCPServer` listenting on `host:port` and adds it as a socket, returning the local address
# and port the server listens on.
#
# ```
# server = HTTP::Server.new { }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More related to the implementation than this doc, but initializing with an empty Proc looks a bit weird.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, but these examples are to demonstrate the bind methods, not handlers. So I think this is fine.
We could add some hello world to the handler, but this just adds house not relevant to the immediate purpose.

# server.bind_tcp("127.0.0.100", 8080) # => Socket::IPAddress.new("127.0.0.100", 8080)
# ```
#
# If *reuse_port* is `true`, it enables the `SO_REUSEPORT` socket option,
# which allows multiple processes to bind to the same port.
def bind_tcp(host : String, port : Int32, reuse_port : Bool = false) : Socket::IPAddress
Expand All @@ -144,6 +149,11 @@ class HTTP::Server
# Creates a `TCPServer` listenting on `127.0.0.1:port` and adds it as a socket,
# returning the local address and port the server listens on.
#
# ```
# server = HTTP::Server.new { }
# server.bind_tcp(8080) # => Socket::IPAddress.new("127.0.0.1", 8080)
# ```
#
# If *reuse_port* is `true`, it enables the `SO_REUSEPORT` socket option,
# which allows multiple processes to bind to the same port.
def bind_tcp(port : Int32, reuse_port : Bool = false) : Socket::IPAddress
Expand Down