@@ -110,7 +110,13 @@ sub build_handler ($controller, $destination)
110110 }
111111 }
112112
113- # this needs to be here, since we want to use $send from this context
113+ # NOTE: this method will not send the response if we already sent or if
114+ # the response is not ready. It does not check whether the context is
115+ # consumed altogether, so a manually consumed context with a non-ready
116+ # response will not send anything, likely rendering some kind of error
117+ # page (but not 404). Currently, a PAGI error is raised, informing
118+ # about app returning without sending respnose.
119+ # NOTE: this needs to be here, since we want to use $send from this context
114120 await $ctx -> try_send_res;
115121
116122 # if this is a bridge and bridge did not render, it means we are
@@ -217,6 +223,10 @@ Scripts must be called using C<pagi-server> (or other PAGI-specific software).
217223Running the script using C<perl > does nothing, as the application cannot run
218224itself - it will be built, but it will not set up a webserver.
219225
226+ C<pagi-server > can be obtained separately from L<PAGI::Server> module.
227+ Thunderhorse does not automatically include PAGI::Server as its dependency,
228+ since it is not coupled with any specific PAGI server implementation.
229+
220230=back
221231
222232=head2 The thunderhorse script
@@ -647,7 +657,7 @@ would expect.
647657One unique feature of Thunderhorse is that it does not stop searching for
648658matches once it finds a match. Instead, it gathers a list of matching locations
649659and then proceeds to execute them in order. It stops once one of the handlers
650- consumes the context, which is usually done by sending a response. If no
660+ consumes the context, which is usually done by setting a response body . If no
651661handlers consumed the context, a I<404 Not Found > error page is rendered.
652662
653663This allows for superb flexibility, but has a couple of interesting side
@@ -768,6 +778,30 @@ matching. If we let C<important_auth> run before C<login_page>, for example by
768778setting its order to C<-2 > , it will effectively become a bridge for
769779C<login_page > .
770780
781+ Currently, the context can be consumed by:
782+
783+ =over
784+
785+ =item * Setting the response body in L<Thunderhorse::Context/res>
786+
787+ =item * Setting the response status to one of the statuses which does not require a body
788+
789+ =item * Closing a websocket connection in L<Thunderhorse::Context/ws>
790+
791+ =item * Closing a sse connection in L<Thunderhorse::Context/sse>
792+
793+ =item * Manually sending any response via PAGI, triggering C<response_started > in C<pagi.connection > scope key
794+
795+ =item * Manually consuming the context via L<Thunderhorse::Context/consume> call
796+
797+ =back
798+
799+ This system should be pretty bulletproof, however once you use the last option
800+ and call L<Thunderhorse::Context/consume> , all safety measures are off - it's
801+ now your responsibility to make sure the route handler will render something
802+ eventually. If it doesn't, you will get a low-level PAGI exception and an error
803+ page completely bypassing any Thunderhorse error rendering. Use with caution.
804+
771805=head2 Controllers
772806
773807By default, all routes defined in the application's C<build > method belong to
0 commit comments