Posted by ChrisS (ChrisS), 11 December 2003
My application currently recieves data via TCP/IP sockets.
However I now need to investigate accepting HTTP messages.
Is there a module on the CPAN that anyone knows of that could help me?
Posted by ChrisS (ChrisS), 11 December 2003
I have found:
LWP - But is this only for client side.. or can I use the tools provided in reverse?
also just literally:
SOAP::Transport::HTTP::Server
I have no idea what this is yet...
Any ideas?
Posted by admin (Graham Ellis), 11 December 2003
Hi, Chris .. at the risk of being branded a politician who answers only the questions he wants to rather than the question that was asked ... here's a web server written in Perl that uses only the Socket module that's a part of the standard distribution and one of our own modules to filter. Might provide you with some food for thought. Not sure about modules - I've not bothered for this sort of thing!
Code:#!/usr/local/bin/perl
# httpd requests - echo server
use Socket; use whc_filter;
# Set up listener
$on_port = 8080; $proto = getprotobyname("tcp");
socket (Server, PF_INET, SOCK_STREAM, $proto) || die ("socket"); setsockopt(Server, SOL_SOCKET,SO_REUSEADDR,1) || die ("setsockopt"); $pbind = sockaddr_in($on_port,INADDR_ANY) || die ("sockaddr_in"); bind(Server,$pbind) || die ("bind"); listen(Server,SOMAXCONN) || die ("listen");
# await a contact
@response = <DATA>;
while ($paddr = accept(Client, Server)) { while (<Client>) { push @gotten,$_; if ($_ =~ /^\s*$/) { last;} ($f,$v) = split(/\s+/,$_,2); $param{lc($f)} = $v; }
if ($gotten[0] =~ /^POST/) { read(Client,$data,$param{"content-length:"}); }
whc_filter::scrub(@gotten); print Client @response; print Client @gotten,"</PRE>"; if ($gotten[0] =~ /^POST/) { ($dsay .= $&."<BR>") while ($data =~ s/^(.{1,80})//); print Client "<H4>Posted Data:</H4><CODE>\n"; print Client $dsay,"</CODE>"; } print Client "</BODY></HTML>\n"; close Client; $#gotten = -1; undef %param; }
__END__ HTTP/1.0 200 OK Date: Sun, 18 Apr 1999 13:59:18 GMT Server: Well House Consultants / PAN 1.0 Content-type: text/html
<HTML> <BODY bgcolor=white text=black> You have contacted the Server Echo Service that tells you what your browser sent in its request!<P> <H2>The Data provided to the server was:</H2> <BR><PRE> |
|
and the module
Code:package whc_filter;
# HTML filters.
require 5.003; use strict;
# scrub encodes & < and > in an array into ISO characters # Also replaces hard new line characters with <P> and <BR>
sub scrub (\@) { my ($svar,$k); $svar = \@_; for ($k=0;$k<=$#{$svar};$k++) { $_=$svar->[$k]; s/&/&/g; s/</</g; s/>/>/g; s/\n\r/\n/g; # dos to standard s/\r/\n/g; # mac to standard s/\n{2,}/<P>/g; s/\n/<BR>/g; $svar->[$k] = $_; } }
1; |
|
Posted by ChrisS (ChrisS), 11 December 2003
Thanks Graham..
I'll look into that..
I think Mr O'reilly's book may come in handy on some of thoughs calls!!
Perhaps I can give you a shout if I get stuck
Chris

This page is a thread posted to the opentalk forum
at
www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow
this link.