File: server.rb

package info (click to toggle)
ruby-protocol-http1 0.14.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 264 kB
  • sloc: ruby: 1,146; makefile: 4
file content (33 lines) | stat: -rwxr-xr-x 633 bytes parent folder | download
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