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) def run_filters(request)
proccontext = get_context(request) proccontext = get_context(request)
@filters.each do |filter| @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 end
true true
end end
@ -128,8 +131,13 @@ module Landline
def run_preprocessors(request) def run_preprocessors(request)
proccontext = get_context(request) proccontext = get_context(request)
@preprocessors.each do |preproc| @preprocessors.each do |preproc|
output = catch(:break) do
proccontext.instance_exec(request, &preproc) proccontext.instance_exec(request, &preproc)
true
end end
return false unless output
end
true
end end
# Append postprocessors to request # Append postprocessors to request
@ -146,7 +154,8 @@ module Landline
def process_wrapped(request) def process_wrapped(request)
return false unless run_filters(request) return false unless run_filters(request)
run_preprocessors(request) return false unless run_preprocessors(request)
enqueue_postprocessors(request) enqueue_postprocessors(request)
@children.each do |x| @children.each do |x|
value = x.go(request) value = x.go(request)
@ -155,7 +164,7 @@ module Landline
value = index(request) value = index(request)
return exit_stack(request, value) if value return exit_stack(request, value) if value
@bounce ? exit_stack(request) : _die(404) notfound(request)
rescue StandardError => e rescue StandardError => e
_die(request, 500, backtrace: [e.to_s] + e.backtrace) _die(request, 500, backtrace: [e.to_s] + e.backtrace)
end end
@ -167,6 +176,11 @@ module Landline
response response
end 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 # Try to perform indexing on the path if possible
# @param request [Landline::Request] # @param request [Landline::Request]
# @return [Boolean] true if indexing succeeded # @return [Boolean] true if indexing succeeded