End of stream identifier
Hi there,I want to be able to read a HTTP request from a socket handle until the end of the request is reached. I want to be able to read GETs and POSTs. In the situation of a POST, I want to read both the header and the payload. Here is an example:
# HEADER
POST /file.pl http://HTTP/1.0
Host: http://www.me.dk
Content-Length: 12
Content-Type: html/text
# PAYLOAD
name=surreal
I can read the request if it is a GET with the current code, as there is no payload to read. I am having troubles with POST requests. Here is some code:
my $firstline = <$client>;
# GET /index.html http://HTTP/1.1
$firstline =~ m/^(\w+)\s+(\S+)(?:\s+(\S+))?\r?$/;
$self->{_METHOD} = $1 || '';
$self->{_RESOURSE} = $2 || '';
$self->{_PROTOCOL} = $3 || '';
my @line = ();
my @temp = ();
while(<$client>) {
# if End Of Stream then last...
push(@temp);
print(pop(@temp));
@line = split(/:/);
print($line[0], $line[1]);
}
I am uncertain if the whole read the handle (<$client>) is a clever idea but ultimately, I want some relitively generic code that will both be able to read a GET request as well as a POST with payload (..and eventually a WebDAV and payload).
I look forward to hearing your wise words!
thanks very much in advance.
/S.