From 30d4c9abe0a5fab4c675d226279f978a7c854807 Mon Sep 17 00:00:00 2001 From: Norbert Hartl Date: Thu, 17 Sep 2026 23:09:02 +0200 Subject: [PATCH] Let the adaptor take a prepared handler, not only a class Naming the handler class means execute says handlerClass new and uses the object in the same line - nobody ever holds it, so a handler that has to be told something cannot be told anything. A metrics endpoint that has to know which domains it exports, and under which prefix, has nowhere to be told. A handler given as an object is now used as it is; given as a class, a fresh one per request as before. All four existing routes name a class and are untouched. Co-Authored-By: Claude Opus 5 (1M context) --- .../HOP-Extra/HOPZincHandlerAdaptor.class.st | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/source/HOP-Extra/HOPZincHandlerAdaptor.class.st b/source/HOP-Extra/HOPZincHandlerAdaptor.class.st index 76c0419..8c173b8 100644 --- a/source/HOP-Extra/HOPZincHandlerAdaptor.class.st +++ b/source/HOP-Extra/HOPZincHandlerAdaptor.class.st @@ -3,7 +3,8 @@ Class { #superclass : 'HOPCatchAllSegment', #instVars : [ 'routeMatch', - 'handlerClass' + 'handlerClass', + 'handler' ], #category : 'HOP-Extra', #package : 'HOP-Extra' @@ -26,12 +27,26 @@ HOPZincHandlerAdaptor >> atMethod: aString ifAbsent: aBlock [ { #category : 'execution' } HOPZincHandlerAdaptor >> execute [ - ^ handlerClass new handleRequest: routeMatch request + ^ self handler handleRequest: routeMatch request +] + +{ #category : 'accessing' } +HOPZincHandlerAdaptor >> handler [ + "A handler given as an object is used as it is; given as a class, a fresh one per request." + ^ handler ifNil: [ handlerClass new ] +] + +{ #category : 'accessing' } +HOPZincHandlerAdaptor >> handler: anObject [ + "Anything that answers handleRequest: with a ZnResponse. Naming the class instead leaves + nobody a moment to configure it - the object is born inside execute and used in the same + line, so a handler that has to be told something cannot be told anything." + handler := anObject ] { #category : 'public' } HOPZincHandlerAdaptor >> handleRoute: aRouteMatch [ - ^ handlerClass new handleRequest: aRouteMatch request + ^ self handler handleRequest: aRouteMatch request ] { #category : 'accessing' }