mirror of
https://github.com/element-hq/synapse.git
synced 2026-03-30 23:45:43 +00:00
Created synapse/http/aiohttp_shim.py: - SynapseRequest — wraps aiohttp.web.Request (or works standalone for tests) with full backward-compatible API: args, content, method, path, uri, requestHeaders, responseHeaders, setResponseCode, setHeader, write, finish, getClientAddress, getClientIP, processing(), request_metrics, logcontext, etc. - SynapseSite — data-only class holding site configuration, no Twisted inheritance - ShimRequestHeaders/ShimResponseHeaders — Twisted Headers API over aiohttp/dict headers - aiohttp_handler_factory — creates aiohttp catch-all handler that dispatches to JsonResource - SynapseRequest.for_testing() — creates test requests without a real aiohttp request Refactored synapse/http/server.py: - Removed Resource inheritance from _AsyncResource, JsonResource, etc. - Removed render(), NOT_DONE_YET, _ByteProducer, failure.Failure usage - Simplified respond_with_json — direct write instead of producer/thread path - Updated error handlers to accept Exception instead of Failure Refactored synapse/http/site.py: - Now a thin re-export layer from aiohttp_shim Updated synapse/app/_base.py: - listen_http() creates aiohttp.web.Application with the shim handler - start_reactor() uses asyncio event loop instead of Twisted reactor - Removed asyncioreactor.install(), listen_ssl(), Twisted reactor dependencies Updated test infrastructure (tests/server.py): - make_request uses SynapseRequest.for_testing() and dispatches via asyncio.ensure_future(resource._async_render_wrapper(req)) - FakeChannel reads response from shim request's buffer Status: The handler dispatch chain works end-to-end (verified manually). Tests that don't involve event persistence pass. Tests that create rooms/register users still timeout due to the pre-existing NativeClock pump issue (batching queue needs clock.advance(0) between event loop iterations).