D
D
Dmitry Mushtat2014-03-20 18:54:19
ruby
Dmitry Mushtat, 2014-03-20 18:54:19

Webrick request handler error - how to fix?

Good day.
I am writing a primitive web server in ruby, without rails.
I use standard http-server webrick
Faced such problem.
When accessing a non-existent file by URL, it gives an error that the file was not found (which is logical).
How can I get a custom server response if the file is not found?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2014-03-21
@fuCtor

I would not fence the bike, but I would recommend then to deal with Rack, then it does not matter which server lies below.
habrahabr.ru/post/131429
And so, if you understand the documentation correctly, then you do something like this:

myserver.mount_proc '/some/path', do |*args|
#.... 
end

I think you can see something arrives in args, in theory there should be request and response objects. From the first one, you can find out what was requested, conduct a check. If the file exists, then upload the file, otherwise upload your text.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question