Sha256: 0b1f3490ff19a0787993b3fe7a46ada33ac6d514ec24f295ab5d7e08437dc6ca
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
#!/usr/bin/env ruby require 'async' require 'async/io/host_endpoint' require 'async/io/ssl_endpoint' require 'async/http/server' require 'async/http/client' require 'localhost/authority' # The (self-signed) authority to use: hostname = "localhost" authority = Localhost::Authority.fetch(hostname) # The server app: app = lambda do |request| Async::HTTP::Response[200, {}, ["Hello World!"]] end # Bind to the specified host: endpoint = Async::IO::Endpoint.tcp(hostname, "8080") # Prepare the server, endpoint will be used for `bind`: server_endpoint = Async::IO::SSLEndpoint.new(endpoint, ssl_context: authority.server_context) server = Async::HTTP::Server.new(app, server_endpoint, Async::HTTP::Protocol::HTTP1) # Prepare the client, endpoint will be used for `connect`: client_endpoint = Async::IO::SSLEndpoint.new(endpoint, ssl_context: authority.client_context) client = Async::HTTP::Client.new(client_endpoint, Async::HTTP::Protocol::HTTP1) # Run the reactor: Async::Reactor.run do |task| # Start the server task: server_task = task.async do server.run end # Connect to the server: response = client.get("/") puts "Status: #{response.status}\n#{response.read}" # Stop the server: server_task.stop end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
localhost-1.1.6 | examples/https.rb |
localhost-1.1.5 | examples/https.rb |