[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Webrick HTTP Errors?

Christian Kerth

5/15/2008 7:39:00 AM

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

1 Answer

GOTO Kentaro

5/15/2008 9:22:00 AM

0

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@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?
>
> thx
> --
> Posted via http://www.ruby-....
>
>