Class: H2::Server::HTTPS
- Inherits:
-
H2::Server
- Object
- H2::Server
- H2::Server::HTTPS
- Defined in:
- lib/h2/server/https.rb
Overview
‘h2’ server - for TLS 1.2 ALPN HTTP/2 connection
Constant Summary collapse
- ALPN_PROTOCOL =
'h2'
- ALPN_SELECT_CALLBACK =
->(ps){ ps.find { |p| ALPN_PROTOCOL == p }}
- ECDH_CURVES =
'P-256'
- TMP_ECDH_CALLBACK =
->(*_){ OpenSSL::PKey::EC.new 'prime256v1' }
- ECDH_OPENSSL_MIN_VERSION =
'2.0'
Constants inherited from H2::Server
Instance Method Summary collapse
-
#initialize(host:, port:, sni: {}, **options, &on_connection) ⇒ HTTPS
constructor
create a new h2 server that uses SNI to determine TLS cert/key to use.
-
#run ⇒ Object
accept a socket connection, possibly attach spy, hand off to
#handle_connection
asyncronously, repeat.
Methods inherited from H2::Server
#goaway, #handle_connection, #handle_push_promise, #handle_stream, #shutdown
Constructor Details
#initialize(host:, port:, sni: {}, **options, &on_connection) ⇒ HTTPS
create a new h2 server that uses SNI to determine TLS cert/key to use
SNI options with default callback
- :sni
-
Hash with domain name
String
keys andHash
values: - :cert
-
String
TLS certificate - :extra_chain_cert
-
String
TLS certificate - :key
-
String
TLS key
SNI options with custom callback
- :sni
-
Hash:
- :callback
-
Proc
createsOpenSSL::SSL::SSLContext
for eachconnection
43 44 45 46 47 48 49 50 |
# File 'lib/h2/server/https.rb', line 43 def initialize host:, port:, sni: {}, **, &on_connection @sni = sni @sni_callback = @sni[:callback] || method(:sni_callback) @tcpserver = Celluloid::IO::TCPServer.new host, port @sslserver = Celluloid::IO::SSLServer.new @tcpserver, create_ssl_context() .merge! host: host, port: port, sni: sni super @sslserver, , &on_connection end |
Instance Method Details
#run ⇒ Object
accept a socket connection, possibly attach spy, hand off to #handle_connection
asyncronously, repeat
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/h2/server/https.rb', line 55 def run loop do begin socket = @server.accept rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::EPIPE, Errno::ETIMEDOUT, Errno::EHOSTUNREACH => ex Logger.warn "Error accepting SSLSocket: #{ex.class}: #{ex.to_s}" retry end async.handle_connection socket end end |