Module: Roda::RodaPlugins::Halt

Defined in:
lib/roda/plugins/halt.rb

Overview

The halt plugin augments the standard request halt method to allow the response status, body, or headers to be changed when halting.

After loading the halt plugin:

plugin :halt

You can call the halt method with an integer to set the response status and return:

route do |r|
  r.halt(403)
end

Or set the response body and return:

route do |r|
  r.halt('body')
end

Or set both:

route do |r|
  r.halt(403, 'body')
end

Or set response status, headers, and body:

route do |r|
  r.halt(403, {'Content-Type'=>'text/csv'}, 'body')
end

Note that there is a difference between provide status, headers, and body as separate arguments and providing them as a single rack response array. With a rack response array, the values are used directly, while with 3 arguments, the headers given are merged into the existing headers and the given body is written to the existing response body.

Defined Under Namespace

Modules: RequestMethods