develooper Front page | perl.libwww | Postings from March 2001

type=<typecode>, last for today I think

Thread Next
From:
Bill_Melvin/SUNY%SUNY
Date:
March 15, 2001 09:59
Subject:
type=<typecode>, last for today I think
Message ID:
OF8B5C1947.5E414AB7-ON85256A10.00613907@esc.edu
Hi all ...

Well, I tracked it down to $remote_file becoming a reference to
a URI::_segment object somehow when there is a ;parameter in the
url. With "print $response->as_string" I get:

500 (Internal Server Error) Can't locate object method "path" via \
     package "URI::_segment"
Client-Date: Thu, 15 Mar 2001 17:11:23 GMT

And we choke right after calling LWP::MediaTypes::guess_media_type
(line 151 Protocol/ftp.pm) right abt here (line 106 MediaTypes.pm):

    if (ref($file)) {
        # assume URI object
        $file = $file->path;

This seems to happen as a result of the $url->path_segments call
around line 116 of Protocol/ftp.pm. I am getting hungry so I am
going to go for the quick-n-dirty right now but since the pod in
URI sez:

     ... Path segments that have parameters are returned as an
     anonymous array. ...

all my RFC'ing could have been replaced with some RTFM'ing :-\

Passing $remote_file to guess_media_types() in ""'s seems to fix
this part and using params() from the old URI::URL to test for
params lets me do the binary/ascii check so I am going to patch
(below).

Is there any way URI could [re]acquire the params() method and
Protocol::ftp check for "type=a"? ;>

Anyway, thanks for listening :-)

/b

--- begin patch ---

# diff -c ftp.pm.orig ftp.pm
*** ftp.pm.orig     Thu Mar 15 10:52:15 2001
--- ftp.pm     Thu Mar 15 12:14:17 2001
***************
*** 13,18 ****
--- 13,19 ----
  use HTTP::Response ();
  use LWP::MediaTypes ();
  use File::Listing ();
+ use URI::URL;

  require LWP::Protocol;
  @ISA = qw(LWP::Protocol);
***************
*** 116,127 ****
      my $remote_file = pop(@path);
      $remote_file = '' unless defined $remote_file;

! #    my $params = $url->params;
! #    if (defined($params) && $params eq 'type=a') {
! #  $ftp->ascii;
! #    } else {
     $ftp->binary;
! #    }

      for (@path) {
     LWP::Debug::debug("CWD $_");
--- 117,128 ----
      my $remote_file = pop(@path);
      $remote_file = '' unless defined $remote_file;

!   my $params = URI::URL->new("$url")->params;
!   if (defined($params) && $params eq 'type=a') {
!    $ftp->ascii;
!     } else {
     $ftp->binary;
!     }

      for (@path) {
     LWP::Debug::debug("CWD $_");
***************
*** 147,153 ****
     my $data;  # the data handle
     LWP::Debug::debug("retrieve file?");
     if (length($remote_file) and $data = $ftp->retr($remote_file)) {
!        my($type, @enc) = LWP::MediaTypes::guess_media_type($remote_file);
         $response->header('Content-Type',   $type) if $type;
         for (@enc) {
          $response->push_header('Content-Encoding', $_);
--- 148,154 ----
     my $data;  # the data handle
     LWP::Debug::debug("retrieve file?");
     if (length($remote_file) and $data = $ftp->retr($remote_file)) {
!        my($type, @enc) = LWP::MediaTypes::guess_media_type("$remote_file");
         $response->header('Content-Type',   $type) if $type;
         for (@enc) {
          $response->push_header('Content-Encoding', $_);



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About