1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#!/usr/bin/env ruby
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2022, by Samuel Williams.
$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
require 'async'
require 'async/http/endpoint'
RESPONSE = <<~HTTP.split(/\r?\n/).join("\r\n")
HTTP/1.1 103 Early Hints
Link: </style.css>; rel=preload; as=style
Link: </script.js>; rel=preload; as=script
HTTP/1.1 200 OK
Content-Length: 11
Connection: close
Content-Type: text/plain
Hello World
HTTP
p RESPONSE
Async do
endpoint = Async::HTTP::Endpoint.parse("http://localhost:3000")
endpoint.accept do |peer|
peer.write(RESPONSE)
end
end
|