Class: Async::Matrix::Endpoint

Inherits:
HTTP::Endpoint
  • Object
show all
Defined in:
lib/async/matrix/endpoint.rb

Overview

Extends Async::HTTP::Endpoint with Matrix well-known discovery. spec.matrix.org/v1.9/client-server-api/#well-known-uri

A server at example.com may serve clients from a completely different origin — e.g. matrix.example.com:8448. #discover resolves that indirection as a proper async I/O operation before constructing the Endpoint, so every downstream caller gets a correctly-pointed connection pool for free.

Constant Summary collapse

WELL_KNOWN =
"/.well-known/matrix/client"

Class Method Summary collapse

Class Method Details

.discover(domain, **options) ⇒ Object

Resolves homeserver base URL, falls back to domain. Must be called inside an Async block — uses the running scheduler.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/async/matrix/endpoint.rb', line 26

def self.discover(domain, **options)
	internet = Async::HTTP::Internet.new
	data     = JSON.parse(internet.get("https://#{domain}#{WELL_KNOWN}").read)
	base_url = data.dig("m.homeserver", "base_url") || "https://#{domain}"
	parse(base_url, **options)
rescue StandardError
	# Well-known is optional per spec — fall back gracefully
	parse("https://#{domain}", **options)
ensure
	internet&.close
end