Christian Kerth | 15 May 09:36
Picon

Webrick HTTP Errors?

Hey

How do i set the HTTP Error Code Header when using webrick.

I found the response.set_error function. What do i need to pass there to
e.g. set a http 404 error?

thx
--

-- 
Posted via http://www.ruby-forum.com/.

GOTO Kentaro | 15 May 11:21
Picon

Re: Webrick HTTP Errors?

Use raise to set status in WEBrick.  For example,

require "webrick"
s = WEBrick::HTTPServer.new(:Port => 2000)
s.mount_proc("/"){|req, res|
  res.body = "ok"
  raise WEBrick::HTTPStatus::OK
}
s.mount_proc("/404"){|req, res|
  raise WEBrick::HTTPStatus::NotFound
}
trap("INT"){s.shutdown}
s.start

This server returns 404 for http://localhost:2000/404
but return 200 for other urls.

HTH,

Gotoken

On Thu, May 15, 2008 at 4:39 PM, Christian Kerth
<christian.kerth <at> dynamicmedia.at> wrote:
> Hey
>
> How do i set the HTTP Error Code Header when using webrick.
>
> I found the response.set_error function. What do i need to pass there to
> e.g. set a http 404 error?
>
(Continue reading)


Gmane