Hello again,
I was hard working on my problem (I've HTTP::Request and I to move its
iformation to CGI object) and I come to the smallest code. But it still does not
work and I do not know where can be a problem.
8<--cut
#!/usr/bin/perl
use strict;
use HTTP:

aemon ();
use CGI ();
my $daemon = HTTP:

aemon->new(
LocalAddr => 'my.domain.com',
LocalPort => 8888,
) or die "Cannot start daemon: $!\n";
my $i;
while (my $conn = $daemon->accept()) {
while (my $req = $conn->get_request()) {
my $url = $req->uri();
$ENV{'REQUEST_METHOD'}=$req->method();
$ENV{'CONTENT_TYPE'}=$req->header('Content-Type');
$ENV{'CONTENT_LENGTH'}=$req->header('Content-Length');
my $filename="/dev/shm/tmp.$$.".++$i;
print STDERR "$filename\n";
open INPUT, ">$filename" or die; # prepare stdin for CGI.pm
binmode INPUT;
print INPUT $req->content;
close INPUT;
open STDIN, "<$filename" or die; # redirect stdin
my $q = CGI->new;
my $id=$q->param('id');
my $ff=$q->param('file');
print STDERR "$id-$ff----\n";
my $res = HTTP::Response->new();
$res->header('Content-Type'=> 'text/html');
my $content=$q->start_html.$q->end_html;
$res->content_length(length($content));
$res->content($content);
$conn->send_response($res);
close STDIN;
}
$conn->close();
}
8<---cut
In first while loop is everything correct. But second and all additional loops
have the same content of $q as in first loop!!!!
STDERR look like this:
/dev/shm/tmp.18353.1
4159616-4159616.jpg----
/dev/shm/tmp.18353.2
4159616-4159616.jpg----
/dev/shm/tmp.18353.3
4159616-4159616.jpg----
It means $q->param('id') returns id from the first file, which contain:
$ head -n5 /dev/shm/tmp.18353.1
--xYzZY
Content-Disposition: form-data; name="id"
4159616
--xYzZY
but it should return id from the second file, which contain:
$ head -n5 /dev/shm/tmp.18353.2
--xYzZY
Content-Disposition: form-data; name="id"
4159620
--xYzZY
If I try to dump STDIN after the line:
open STDIN, "<$filename" or die; # redirect stdin
it is the same as content of file $filename
But CGI module somehow remember its state from first reading!!
How can I force CGI to re-read STDIN?
Or make I something wrong?
BTW: The request for this daemon is created using this code:
....
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://my.domain.com:8888/',
[
id => $id,
file => ["$path$id.jpg"] ,
],
'Content_Type' => 'form-data',
);
Thanks in advance for any suggestion
Miroslav Suchy