Best way to have a perl-base self contained HTTP Server that also manages TCP connections
I am writing a small glue tool for doing some testing and I would like to heavily leverage CPAN. My tool must act as an HTTP server to bridge posted data to other TCP connections and vi开发者_如何学运维ce-versa.
I have started the tool using IO::Event, which has been working very well for me. I would like to integrate it with something like HTTP::Server::Simple to do the HTTP parsing for me rather than muck around with parsing the HTTP headers myself. A quick perusal of HTTP::Server::Simple didn't seem like it could just work, but perhaps I missed something.
Has anyone done something like this?
After searching CPAN some more, I have found the module: HTTP::Parser. It appears to do exactly what I want.
Combining IO::Event and HTTP::Parser makes a very straightforward application for doing exactly what I want with a minimum amount of fuss.
Update: One thing that I should mention is that IO::Event by default will not handle binary data very well. It tries to use perl's buffered IO, which will try to deliver data according to the record separator. You can get around this by setting '$client->autoread(0);'. Once you do this, you have to use 'ie_read_ready()' events and do an explicit 'recv' call to get the data on the underlying filehandle. To send data, do a 'send' call on the underlying filehandle. This worked well for me.
精彩评论