Reading a HTTP request

[b][red]This message was edited by saridski at 2006-6-29 5:37:12[/red][/b][hr]
Hi there,

I want to be able to read a HTTP request from a 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/1.0
Host: www.me.dk
Content-Length: 13
Content-Type: html/text

# PAYLOAD
name=saridski

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/1.1
$firstline =~ m/^(w+)s+(S+)(?:s+(S+))?
?$/;
$self->{_METHOD} = $1 || '';
$self->{_RESOURSE} = $2 || '';
$self->{_PROTOCOL} = $3 || '';

my @line = ();
my @temp = ();
while(<$client>) {
# In the case that this is a GET the next line will be OK
# If it is a POST then the payload will not be read
last if ($_ eq "1512");
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.







Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories