Re: LWP and $content

ts (decoux@moulon.inra.fr)
Mon, 7 Aug 1995 10:46:59 +0200


> >  What about making no modification but :
> > 
> >     if(ref($content) eq "SCALAR") {
> >         $senddata .= $$content;
> >     } elsif(ref($content) ne "CODE") {
> >         $senddata .= $content;
> >     }
> > 
> >     $socket->write($senddata);
> >     &$content($socket) if ref($content) eq "CODE";
> > 
> > 
> >  With this, an application can put it's specific sub to send the content, no ?
> 
> Yes it should work for http, but I don't like to give out the filedescriptor.  
> There might be protcols where this will not be appropriate (for instance 
> mailto based on Mail::Send).  I would rather see an interface more like the 
> one for content in the response.

 Hey, I've made this modification in LWP::Protocol::http.pm !
 This module don't handle `mailto:', it handle only `http:' !

> 
> I.e., the callback is supposed to return a reference to a chunk of content 
> each time and LWP handles sockets internally.  For http we must also ensure 
> that the length of the content corresponds to the Content-Length: header.
> 

 I compute the value of Content-Length, and I had this header line before 
calling LWP::Request.


> Another issue:  How do we allow requests to be terminated prematurely from the 
> program (the user hits the "Stop" button)?
> 

 Actually this sub return :
   * 0 if it's OK
   * a positive value, if the transfert was interrupted.

 You can perhaps check the return value.


 For example, this is actually my interface :

  if($method eq "POST") {
    ${$w->{-header}}{'Content-Type'} = $enctype;
    if($upload ne "") {
      ${$w->{-header}}{'Content-Length'} = (stat($upload))[7];
      my $ref_post = &sub_post($w,$upload);
      $w->HREF($action,"POST",$ref_post);
    } else {
      $w-HREF($action,"POST",$query);
    }
  } else {
    $w->HREF("$action?$query");
 }

 with :

sub sub_post {
  my($w,$file) = @_;
  return sub {
    my($arg) = @_;
    my $socket = $arg->{'socket'};
    my $BAR = "BAR";
    $w->{'url_post'} = 0;
    if(open($BAR,"<$file")) {
      $w->{'url_post'} = -1;
      $w->fileevent($socket,'writable',['post_OK',$w,$BAR,$socket]);
      $w->tkwait('variable',\$w->{'url_post'});
      close($BAR);
    }
    unlink($file);
    return $w->{'url_post'};
  }
}

 i.e. I don't want use the sub Socket::write, because there is no timeout
in this sub, and I can send *huge* file. You have at the end an example
of what I want send, and imagine that the user has selected a file like
`perl5.001m.tar.gz'.


Guy Decoux


 -----------------------------------------------------------------------------
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="file"
Content-type: multipart/mixed, boundary=aghgHFJjjHJAfAexr09039147808674875674

--aghgHFJjjHJAfAexr09039147808674875674
Content-disposition: attachement; filename="form.html"
Content-type: text/html
Content-Transfer-Encoding: binary

<HEAD><TITLE>Columns CARTE_BIBLIO</TITLE>
<ISINDEX>
</HEAD><BODY><H2>Columns for CARTE_BIBLIO</H2>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="/cgi-bin/dump.pl">
<INPUT type=submit VALUE=Table><INPUT type=reset value=reset><p>
<HR>Maximum number of rows : <input name="maxs" size=10 maxlength=10 value="1000">
<p><input type=file name=file size="35,1"><br>
Select<p> <br>au revoir
<br><input type=radio name=radio value=unique> only distinct rows
<br><input type=radio name=radio value=all checked> all rows
<br><input type=checkbox name=checkbox value=unique checked> only distinct rows
<br><input type=checkbox name=checkbox value=all> all rows
<br>select from CARTE_BIBLIO where : <INPUT name="selection" size=56><hr><pre>
       Position     Length      Order
<B>CARTE </B><INPUT type=password NAME="source_CARTE" size=6 maxlength=3 VALUE="1">       <INPUT NAME="longueur_CARTE" size=6 maxlength=4 VALUE="10">       <INPUT NAME="ordre_CARTE" size=6 maxlength=5>
<B>REF   </B><INPUT NAME="source_REF" size=6 maxlength=3 VALUE="2">       <INPUT NAME="longueur_REF" size=6 maxlength=4 VALUE="5">       <INPUT NAME="ordre_REF" size=6 maxlength=5>
</pre>
<input type=image name=aa src="saturn.gif">
<SELECT NAME="flavor" multiple>
<OPTION>Vanilla
<OPTION>Strawberry
<OPTION value="RumRasin">Rum and Raisin
<OPTION selected>Peach and Orange
</SELECT>
<SELECT NAME="brown">
<OPTION>Vanilla
<OPTION>Strawberry
<OPTION value="RumRasin">Rum and Raisin
<OPTION selected>Peach and Orange
</SELECT>
<TEXTAREA cols=14 rows=5 name=textarea>bonjour
au revoir
</textarea>
</FORM><HR></BODY>
aghgHFJjjHJAfAexr09039147808674875674--
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="brown"

Vanilla
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="longueur_REF"

5
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="source_REF"

2
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="radio"

all
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="checkbox"

unique
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="maxs"

1000
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="textarea"

bonjour
au revoir

--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="longueur_CARTE"

10
--aghgHFJjjHJAfAexr09039147808674875673
content-disposition: form-data; name="source_CARTE"

1
aghgHFJjjHJAfAexr09039147808674875673--
 ------------------------------------------------------------------------------