Fix for bounce not working in preprocess and filter blocks

This commit is contained in:
Yessiest 2024-05-06 02:33:02 +04:00
parent dd791ca5d1
commit de59eea736
1 changed files with 18 additions and 4 deletions

View File

@ -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