You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Silent <si...@gmail.com> on 2007/12/02 05:24:08 UTC

mp1 internal_redirect question

Hi,

I want to develop a script like this:

the script randomly send a html page or mp3 file, but I met some problems,


#!/usr/bin/perl

use Apache;
my $r=Apache->request;

my @file = ( { '/1.mp3' => 'audio/mpeg' },
             { '/aaa.html' => 'text/html' },
             { '/bbb.html' => 'text/html' },
             { '/1.png' => 'image/png'}
    );

my $idx = int rand(4);
my @ks = keys %{$file[$idx]};
my $key = shift @ks;

warn("$file[$idx]{$key} -- $key");  # log

$r->content_type($file[$idx]{$key});  # content-type

#$r->send_http_header;            # this seems can be omited

$r->internal_redirect_handler($key);  #  redirect to file , also tryed
"internal_redirect"

#### end

 I am using apache1.3.x+mod_perl 1.29

<IfModule mod_perl.c>
  PerlModule Apache::Registry
  <IfModule mod_alias.c>
   Alias /perl/ /var/www/perl/
  </IfModule>
  <Location /perl>
    SetHandler perl-script
    PerlHandler Apache::Registry
    Options +ExecCGI
  </Location>
</IfModule>

the url is http://192.168.0.1/rand/asd.mp3 ,          rand is the script
name, asd.mp3 is just a fake path_info.

tested with MSIE6 and firefox2 on windowsXP-pro-sp2,

firefox2 works fine, when mp3 file reached, it ask for download or play

MSIE6 sometimes works,
but sometimes:
1. sometimes text file was processed by windows mediaplayer
2. sometimes png file was processed by windows mediaplayer
3. sometimes mp3 file was showed as text file, (losts of non-string char in
IE)

and I am sure the content-type is sended correctly (watching the log warn)

are the problems as IE6 natures ?
is there any other proper way to do this ?



question 2:
with mod_perl2, internal_redirect seems can access system file, such as
/etc/*, but mod_perl1 seems can only access files under apache documentroot
right ?

thanks!

Re: mp1 internal_redirect question

Posted by Perrin Harkins <pe...@elem.com>.
On Dec 7, 2007 5:01 PM, Ronald Dai. <Ro...@proexam.org> wrote:
> Because it is somehting like
>
> eval{ do something; warn " warning message"}  or die "dying message";
>
> Neither warning message nor dying message was logged.

That could mean that it crashed before the warning, or it could mean
something messed with STDERR, or installed a $SIG{__WARN__} handler.

- Perrin

RE: mp1 internal_redirect question

Posted by "Ronald Dai." <Ro...@proexam.org>.
Because it is somehting like 
 
eval{ do something; warn " warning message"}  or die "dying message";
 
Neither warning message nor dying message was logged.
 
Thanks
Ron

________________________________

From: pharkins@gmail.com on behalf of Perrin Harkins
Sent: Fri 12/7/2007 4:57 PM
To: Ronald Dai.
Cc: modperl@perl.apache.org
Subject: Re: mp1 internal_redirect question



I think you've responded to the wrong thread here...

On Dec 7, 2007 4:49 PM, Ronald Dai. <Ro...@proexam.org> wrote:
> For a
> eval{} or die "" block if the message of die was not logged, I guess the
> process got aborted within the eval block....

That's a pretty big guess.  How do you know it didn't complete the
eval block?  How do you know it died?

- Perrin



Re: mp1 internal_redirect question

Posted by Perrin Harkins <pe...@elem.com>.
I think you've responded to the wrong thread here...

On Dec 7, 2007 4:49 PM, Ronald Dai. <Ro...@proexam.org> wrote:
> For a
> eval{} or die "" block if the message of die was not logged, I guess the
> process got aborted within the eval block....

That's a pretty big guess.  How do you know it didn't complete the
eval block?  How do you know it died?

- Perrin

RE: mp1 internal_redirect question

Posted by "Ronald Dai." <Ro...@proexam.org>.
Perrin:
 
Good info....I will make note of it....But our situation might be a bit different. Within the block that failed is a MIME::Lite::SMTP mail sending call. The content of the mail is standardized for everyone except for name etc. For most people, it either does not fail or fail with error message logged.....but sometimes it failed without loggin any error message. For a eval{} or die "" block if the message of die was not logged, I guess the process got aborted within the eval block....I tested many ways, but could not figure out how the process could be aborted within the eval block....
 
Thanks
Ron

________________________________

From: pharkins@gmail.com on behalf of Perrin Harkins
Sent: Fri 12/7/2007 4:45 PM
To: Silent
Cc: modperl@perl.apache.org
Subject: Re: mp1 internal_redirect question



On Dec 6, 2007 8:36 PM, Silent <si...@gmail.com> wrote:
> # my mod_rerite.conf
> # section 1
> RewriteEngine On
> RewriteCond %{HTTP_USER_AGENT} Firefox  [OR]
> RewriteCond %{HTTP_USER_AGENT} lwp-request [OR]
> RewriteRule ^/mp3/aaa\.mp3$            /mp3/aaa.html
>
> # section 2
> RewriteCond %{HTTP_USER_AGENT} MSIE
> RewriteRule /fake.html         /mp3/bbb.mp3

You can do all of that in a PerlTransHandler with an internal redirect.

> I just add section 2 now, but when I access http://../fake.html  with IE,
> windows media-player auto-lanched, but can not play the file, maybe because
> the filename is html

Usually it's the MIME-Type that matters, but IE is notorious for
looking at file extensions.

- Perrin



Re: mp1 internal_redirect question

Posted by Perrin Harkins <pe...@elem.com>.
On Dec 6, 2007 8:36 PM, Silent <si...@gmail.com> wrote:
> # my mod_rerite.conf
> # section 1
> RewriteEngine On
> RewriteCond %{HTTP_USER_AGENT} Firefox  [OR]
> RewriteCond %{HTTP_USER_AGENT} lwp-request [OR]
> RewriteRule ^/mp3/aaa\.mp3$            /mp3/aaa.html
>
> # section 2
> RewriteCond %{HTTP_USER_AGENT} MSIE
> RewriteRule /fake.html         /mp3/bbb.mp3

You can do all of that in a PerlTransHandler with an internal redirect.

> I just add section 2 now, but when I access http://../fake.html  with IE,
> windows media-player auto-lanched, but can not play the file, maybe because
> the filename is html

Usually it's the MIME-Type that matters, but IE is notorious for
looking at file extensions.

- Perrin

Re: mp1 internal_redirect question

Posted by Silent <si...@gmail.com>.
# my mod_rerite.conf
# section 1
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} Firefox  [OR]
RewriteCond %{HTTP_USER_AGENT} lwp-request [OR]
RewriteRule ^/mp3/aaa\.mp3$            /mp3/aaa.html

# section 2
RewriteCond %{HTTP_USER_AGENT} MSIE
RewriteRule /fake.html         /mp3/bbb.mp3

# EOF

in section 1
firefox / lwp can only get a html page, and IE or other agent will got the
mp3 and play,

I just add section 2 now, but when I access http://../fake.html  with IE,
windows media-player auto-lanched, but can not play the file, maybe because
the filename is html

lwp,
#HEAD http://192.168.1.2/fake.html <http://192.168.1.217/fake.html>
200 OK
Connection: close
Date: Fri, 07 Dec 2007 01:22:13 GMT
Accept-Ranges: bytes
ETag: "fec34-22bee2-f884a000"
Server: Apache/2.2.4 (Fedora) DAV/2 mod_perl/2.0.3 Perl/v5.8.8
Content-Length: 2277090
Content-Type: audio/mpeg
Last-Modified: Fri, 07 Dec 2007 01:14:40 GMT
Client-Date: Fri, 07 Dec 2007 01:22:13 GMT
Client-Peer: 192.168.1.217:80
Client-Response-Num: 1






2007/12/7, Perrin Harkins <pe...@elem.com>:
>
> On Dec 5, 2007 11:15 PM, Silent <si...@gmail.com> wrote:
> > I tryed mod_rewrite to redirect base on user_agent, it works very fine!
> > but I still want to know how to do it in mod_perl.
>
> Can you tell us what you did in mod_rewrite?  Then we can show you an
> equivalent for mod_perl.
>
> - Perrin
>

Re: mp1 internal_redirect question

Posted by Perrin Harkins <pe...@elem.com>.
On Dec 5, 2007 11:15 PM, Silent <si...@gmail.com> wrote:
> I tryed mod_rewrite to redirect base on user_agent, it works very fine!
> but I still want to know how to do it in mod_perl.

Can you tell us what you did in mod_rewrite?  Then we can show you an
equivalent for mod_perl.

- Perrin

Re: mp1 internal_redirect question

Posted by Silent <si...@gmail.com>.
I tryed mod_rewrite to redirect base on user_agent, it works very fine!
but I still want to know how to do it in mod_perl.




2007/12/2, Silent <si...@gmail.com>:
>
> Hi,
>
> I want to develop a script like this:
>
> the script randomly send a html page or mp3 file, but I met some problems,
>
>
> #!/usr/bin/perl
>
> use Apache;
> my $r=Apache->request;
>
> my @file = ( { '/1.mp3' => 'audio/mpeg' },
>              { '/aaa.html' => 'text/html' },
>              { '/bbb.html' => 'text/html' },
>              { '/1.png' => 'image/png'}
>     );
>
> my $idx = int rand(4);
> my @ks = keys %{$file[$idx]};
> my $key = shift @ks;
>
> warn("$file[$idx]{$key} -- $key");  # log
>
> $r->content_type($file[$idx]{$key});  # content-type
>
> #$r->send_http_header;            # this seems can be omited
>
> $r->internal_redirect_handler($key);  #  redirect to file , also tryed
> "internal_redirect"
>
> #### end
>
>  I am using apache1.3.x+mod_perl 1.29
>
> <IfModule mod_perl.c>
>   PerlModule Apache::Registry
>   <IfModule mod_alias.c>
>    Alias /perl/ /var/www/perl/
>   </IfModule>
>   <Location /perl>
>     SetHandler perl-script
>     PerlHandler Apache::Registry
>     Options +ExecCGI
>   </Location>
> </IfModule>
>
> the url is http://192.168.0.1/rand/asd.mp3 ,          rand is the script
> name, asd.mp3 is just a fake path_info.
>
> tested with MSIE6 and firefox2 on windowsXP-pro-sp2,
>
> firefox2 works fine, when mp3 file reached, it ask for download or play
>
> MSIE6 sometimes works,
> but sometimes:
> 1. sometimes text file was processed by windows mediaplayer
> 2. sometimes png file was processed by windows mediaplayer
> 3. sometimes mp3 file was showed as text file, (losts of non-string char
> in IE)
>
> and I am sure the content-type is sended correctly (watching the log warn)
>
> are the problems as IE6 natures ?
> is there any other proper way to do this ?
>
>
>
> question 2:
> with mod_perl2, internal_redirect seems can access system file, such as
> /etc/*, but mod_perl1 seems can only access files under apache documentroot
> right ?
>
> thanks!
>

Re: mp1 internal_redirect question

Posted by Perrin Harkins <pe...@elem.com>.
On Dec 1, 2007 11:42 PM, Silent <si...@gmail.com> wrote:
> and I have another server has mod_perl-1.99_09 with apache
> httpd-2.0.46-44.ent on redhat es3 update4
> I want to know: which version mod_perl document is related to mod_perl 1.99,
> 1.x or 2.x ?

1.99 is a pre-release version of mod_perl 2 which contains various
bugs and is not covered by any documentation.  It should not be used.

- Perrin

Re: mp1 internal_redirect question

Posted by Silent <si...@gmail.com>.
>
>  question 2:
> with mod_perl2, internal_redirect seems can access system file, such as
> /etc/*, but mod_perl1 seems can only access files under apache documentroot
> right ?
>
sorry, the second question not correct, the mod_perl2 "sendfile" can access
system file,

and I have another server has mod_perl-1.99_09 with apache
httpd-2.0.46-44.ent on redhat es3 update4
I want to know: which version mod_perl document is related to mod_perl 1.99,
1.x or 2.x ?

thanks again!