Help with GServer

S

Sudhi Kulkarni

Hi,

I have a requirement

when user type http://localhost:8000/1.xml ... the server should return
1.xml contents which is stored in server's local file system.

I wrote ruby script using GServer library but in serve() function how do
I get the query_string basically I want to be able to get that the user
has requested 1.xml some how...

Please help...

Thanks,
Sudhi
 
I

Iñaki Baz Castillo

2009/3/30 Sudhi Kulkarni said:
Hi,

I have a requirement

when user type http://localhost:8000/1.xml ... the server should return
1.xml contents which is stored in server's local file system.

I wrote ruby script using GServer library but in serve() function how do
I get the query_string basically I want to be able to get that the user
has requested 1.xml some how...

I don't understand your problem.

GServer is just a threaded TCP listener, it doesn't work at
application level (as an HTTP server does). So the steps you should do
are:

1) Start GServer.
2) For each *TCP* connection parse the TCP data and extract the first
line to get the requested URL.
3) Do anything with it.

But you should use something as Mongrel which allows this kind of stuf
very easy and ellegant.

--=20
I=C3=B1aki Baz Castillo
<[email protected]>
 
B

Brian Candler

Iñaki Baz Castillo said:
But you should use something as Mongrel which allows this kind of stuf
very easy and ellegant.

For a low-level HTTP app, I'd say use Rack. You just write a single
handler function; each incoming request calls that function, and the
response is what your function returns.

http://rack.rubyforge.org/
http://rack.rubyforge.org/doc/files/SPEC.html

It includes a bunch of modules you can plug in, like Rack::File which
does exactly the sort of static file serving you're talking about. And
the nice thing is you can run your application under any webserver you
like without any modification.

For a higher-level HTTP app, I'd say use Sinatra. Your app becomes as
simple as this (minus security checks):

require 'sinatra'
get '/:id.xml'
send_file "/path/to/#{id}.xml"
end

Sinatra runs on Rack, and you can plugin Rack modules easily.
 
S

Sudhi Kulkarni

Brian said:
For a low-level HTTP app, I'd say use Rack. You just write a single
handler function; each incoming request calls that function, and the
response is what your function returns.

http://rack.rubyforge.org/
http://rack.rubyforge.org/doc/files/SPEC.html

It includes a bunch of modules you can plug in, like Rack::File which
does exactly the sort of static file serving you're talking about. And
the nice thing is you can run your application under any webserver you
like without any modification.

For a higher-level HTTP app, I'd say use Sinatra. Your app becomes as
simple as this (minus security checks):

require 'sinatra'
get '/:id.xml'
send_file "/path/to/#{id}.xml"
end

Sinatra runs on Rack, and you can plugin Rack modules easily.
Hi,

Thanks for the solutions Sinatra and Rack look good but need a bit of
extra installations which I want to avoid for this basic operation...

I like the idea to parse TCP Stram... should I do it in serve()? All I
get as input in serve is a io object of type TCPSocket how do I parse
lines from it? Snippet would be of big help...

Thanks,
Sudhi
 
J

James Gray

Thanks for the solutions Sinatra and Rack look good but need a bit of
extra installations which I want to avoid for this basic operation...

Then use the WEBrick standard library that ships with Ruby.
I like the idea to parse TCP Stram...

No you don't. Trust me. ;)

James Edward Gray II
 
B

Brian Candler

James said:
Then use the WEBrick standard library that ships with Ruby.


No you don't. Trust me. ;)

If you don't trust him: read RFC 2616 from top to bottom. Then you will
trust him :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top