Add HTTP::Server#bind(URI)#6500
Conversation
src/socket/address.cr
Outdated
| # It expects the URI to include `<scheme>://<path>` where `scheme` as well | ||
| # as any additional URI components (such as `fragment` or `query`) are ignored. | ||
| # | ||
| # If `host` is not empty, it will be prepended to `path` to form a relatve |
src/socket/address.cr
Outdated
| # Parses a `Socket::IPAddress` from an URI. | ||
| # | ||
| # It expects the URI to include `<scheme>://<host>:<port>` where `scheme` as | ||
| # well asa ny additional URI components (such as `path` or `query`) are ignored. |
8ce0453 to
9e23371
Compare
src/http/server.cr
Outdated
| address = Socket::IPAddress.parse(uri) | ||
| context = OpenSSL::SSL::Context::Server.parse(HTTP::Params.parse(uri.query || "")) | ||
|
|
||
| bind_ssl(address, context) |
There was a problem hiding this comment.
Checking for flag?(:without_openssl) is missing here. At least with a duplication of the Unsupported socket type message or something more specific.
src/openssl/ssl/context.cr
Outdated
| # | ||
| # context = OpenSSL::SSL::Context::Client.parse({"key" => "private.key", "cert" => "certificate.crt", "ca" => "ca.pem"}) | ||
| # ``` | ||
| def self.parse(params) : self |
There was a problem hiding this comment.
I would expect T.parse to be from String -> T. I would suggest T.from_hash for this method.
src/http/server.cr
Outdated
| bind(URI.parse(uri)) | ||
| end | ||
|
|
||
| # ditto |
There was a problem hiding this comment.
Warn: mixed ditto and :ditto: in the PR
| # Socket::IPAddress.parse("tcp://127.0.0.1:8080") # => Socket::IPAddress.new("127.0.0.1", 8080) | ||
| # Socket::IPAddress.parse("udp://[::1]:8080") # => Socket::IPAddress.new("::1", 8080) | ||
| # ``` | ||
| def self.parse(uri : URI) : IPAddress |
There was a problem hiding this comment.
Somehow I'm ok with T.parse: URI -> T 😹 , but not with Hash.
There was a problem hiding this comment.
URI is essentially a structured string...
9e23371 to
d517ed6
Compare
src/openssl/ssl/context.cr
Outdated
| # | ||
| # Params: | ||
| # | ||
| # * `key` *(required*): Path to private key file. See `#private_key=`. |
There was a problem hiding this comment.
*(required*) -> (*required*)
ditto below
The URI can be parsed from a string and contains the protocol and address to bind to (plus optional additional configuration for SSL context). This allows for a uniform and easily exchangable specificitation in config files.
d517ed6 to
0620467
Compare
sdogruyol
left a comment
There was a problem hiding this comment.
Thank you @straight-shoota 👍
|
The sample in the PR description mention Or am I missing something? |
|
You're absolute right. |
|
Bold proposal: Lets ditch |
|
All the classes in Crystal are called SSL... so I'd at least keep support for |
|
No, they're called |
|
No, I mean inside the But I'd suggest to discuss this further in a new dedicated issue... |
|
I wouldn't be too opposed to renaming that to TLS too :P |
|
|
|
I'll work on that. Waiting for #6530 to be merged. |
|
I realise this has already been merged, but FWIW I would have expected to be able to bind to do |
|
No, this wasn't discussed before explicitly. And I admit that this might look a bit surprising at first. The reason is that The URIs used by The same transport protocol schemes are also used by similar applications such as Puma or Nginx. |
|
Wasn't aware of other servers using these protocols, makes sense. Thanks for the clarification. |
This PR was originally included in #5776 but it had been removed as a separate feature. Now that #5959 and #5960 are merged, it is ready to be reviewed. The original description can be found in #2735 (comment)
The URI can be parsed from a string and contains the protocol and address to bind to (plus optional additional configuration for SSL context). This allows for a uniform and easily exchangeable specification in config files.
Along the way this also adds
Socket::{IP,UNIX,}Address.parseandOpenSSL::SSL::Context::{Client,Server}.parseto implement the individual component parsers.