From de59eea736c5d0b676301f28428306b4a1cb02d8 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Mon, 6 May 2024 02:33:02 +0400 Subject: [PATCH] Fix for bounce not working in preprocess and filter blocks --- lib/landline/path.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/landline/path.rb b/lib/landline/path.rb index 8176ff7..999e361 100644 --- a/lib/landline/path.rb +++ b/lib/landline/path.rb @@ -118,7 +118,10 @@ module Landline def run_filters(request) proccontext = get_context(request) @filters.each do |filter| - return false unless proccontext.instance_exec(request, &filter) + output = catch(:break) do + proccontext.instance_exec(request, &filter) + end + return false unless output end true end @@ -128,8 +131,13 @@ module Landline def run_preprocessors(request) proccontext = get_context(request) @preprocessors.each do |preproc| - proccontext.instance_exec(request, &preproc) + output = catch(:break) do + proccontext.instance_exec(request, &preproc) + true + end + return false unless output end + true end # Append postprocessors to request @@ -146,7 +154,8 @@ module Landline def process_wrapped(request) return false unless run_filters(request) - run_preprocessors(request) + return false unless run_preprocessors(request) + enqueue_postprocessors(request) @children.each do |x| value = x.go(request) @@ -155,7 +164,7 @@ module Landline value = index(request) return exit_stack(request, value) if value - @bounce ? exit_stack(request) : _die(404) + notfound(request) rescue StandardError => e _die(request, 500, backtrace: [e.to_s] + e.backtrace) end @@ -167,6 +176,11 @@ module Landline response end + # Exit with failure or throw 404 + def notfound(request) + @bounce ? exit_stack(request) : _die(request, 404) + end + # Try to perform indexing on the path if possible # @param request [Landline::Request] # @return [Boolean] true if indexing succeeded