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

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 K.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs