You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Neal Rhodes <ne...@dexter.mnopltd.com> on 2003/04/02 19:13:59 UTC

[users@httpd] How to send Binary Files Inline?

Greetings. 

We are trying to figure out where in TFM this might be discussed. 
We are writing a web application, which runs essentially as a CGI
script.   Developing with Apache/1.3.12 on linux, although it will be
running on the current RedHat 7.3 apache once released. 

This is being written in Progress Webspeed, although from apache's
standpoint it appears analagous to being an external CGI script. 

This one detail that has us stumped - we have some .pdf files which 
have been previously run and are sitting on the disk.   And when 
user requests are made, we need to evaluate if that user has a valid
reason to see the .pdf file, and then supply it to them inline as a 
response.  

We cannot do this with static html, since there's a lot of things
which determine this and we don't want to allow url hacking to look
at things one shouldn't. 

So, what we are trying to output to apache is analagous to a script 
that said:


echo "Content-Type:application/pdf"
echo "Content-disposition: attachment; filename=ny000473_speccase_1_1.pdf"
echo " "
cat the-pdf-file.pdf 


And the actual output to apache looks like this:
Content-Type:application/pdf^M
Content-disposition: attachment; filename=ny000473_speccase_1_1.pdf^M
Content-transfer-encoding: base64^M

%PDF-1.2
(and the actual file, in gory binary detail.)


And the end result on the screen is the apache misconfiguration message.


And the error file says:
[Wed Apr  2 09:40:52 2003] [error] [client 209.124.77.249] malformed header from
 script. Bad header=Binary file (standard input) m: /usr/appl/cgi/bdny


Clearly we need to do SOMETHING else to keep apache happy, but we're
at a loss to figure out what.  Any ideas? 

-- 
============================================================================
Neal Rhodes                    MNOP Ltd                       (770) 972-5430
President                  4737 Habersham Ridge         fax:  (770) 978-4741
                          Lilburn (atlanta) GA 30047    

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Method Handler Gives class string, not class Ref

Posted by Martin Moss <Ma...@btinternet.com>.
All,

I'm trying to work out the exact process for method handlers. I have a
method handler, which has a 'new' subroutine and the following handler
process:-

#sub handler : method        #Either of these is fine??????
sub handler ($$)
{

  my ($self,$r)=@_;

  #unless (ref($self))
  #{
    #print STDERR "Making NEW Object!!!!!!!!!\n";
    #$self=$self->new();
  #}

    $r=Bficient::Apache::Request->instance($r);
  my $uh=$r->user_object();
  $self->{user}=$uh;    #Get Error Here!!!! (Can't use string
("Bficient::Admin::Apache::Home") as a HASH ref while "strict refs" in use
at)


    etc.....
}

The problem I have is that $self is a 'classname string' not a class object.
Is this right? I thought that $self should be an object reference.
I'd seen an example in the mod_perl cookbook which treats $self as an
object. So I thought the above code should work, but it doesn't it gives me
an error of

"Can't use string ("Bficient::Admin::Apache::Home") as a HASH ref while
"strict refs" in use at etc..."

I am pre-loading Bficient::Admin::Apache::Home in my startup.pl, as I must
dynamically load modules based upon configuration files.
my 'new' subroutine is:-

sub new
{
  # inherited by all classes
  my $proto = shift;
  my $args=shift;
  my $class = ref($proto) || $proto;
  my $self = {};

  #print STDERR "In Bficient::Apache::Object for
$class\ndefault_task=$_default_task;";
  bless $self, $class;

  if(exists($args->{lang_id}))
  {
    $self->{lh}=Bficient::Maketext->get_handle($class,$args->{lang_id});
  }
  else
  {

$self->{lh}=Bficient::Maketext->get_handle($class,Bficient::Conf::DEFAULT_LA
NGUAGE_ID);
  }

  $self->_check_framework_methods();

  return $self;
}


Can anybody tell me If I'm assuming something that isn't or have I done
something wrong.

Kind regards

Marty


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to send Binary Files Inline?

Posted by Neal Rhodes <ne...@dexter.mnopltd.com>.
Thanks for the reply.   I did the switch to the native redhat 1.3.27
apache, and the other changes noted.  Now my output looks like...

Content-Type: application/pdf^M
Content-disposition: filename=ny000473_speccase_1_1.pdf^M

%PDF-1.2
%Gl~O"
6 0 obj
<</Length 7 0 R/Filter /FlateDecode>>
stream

But we still get...
[Wed Apr  2 14:07:50 2003] [error] [client 209.124.77.249] malformed header 
from script. Bad header=Binary file (standard input) m: /usr/appl/cgi/bdny

I tossed in your " Transfer-Encoding: chunked" in the interest of science, 
but that didn't do anything either. 

Now, PHP is a module, right?  And that's different from apache invoking 
a separate cgi script and reading its StdOut. 

NOW HERE'S THE interesting thing - If I replace the actual .pdf file
with a plain text file that begins with the line %PDF-, then apache is
completely happy.  Of course Acrobat is not really thrilled, but that's
to be expected. 

On Wed, Apr 02, 2003 at 12:32:17PM -0500, Jacob Coby wrote:
> > Clearly we need to do SOMETHING else to keep apache happy, but we're
> > at a loss to figure out what.  Any ideas?
> 
> 1) put a space after the colon in the Content-type header
> 2) take out the attachment clause to Content-Disposition
> 3) upgrade apache to 1.3.27.  This issue may be a bug and already be
> adressed.
> 
> We're doing an analagous thing here, but through php.  The returned headers
> look like:
> 
> HTTP/1.1 200 OK
> Date: Wed, 02 Apr 2003 17:28:30 GMT
> Server: Apache/1.3.27 (Unix) PHP/4.2.3 mod_ssl/2.8.11 OpenSSL/0.9.6g
> X-Powered-By: PHP/4.2.3
> X-Accelerated-By: PHPA/1.3.3r1
> Content-Disposition: filename="useful.txt"
> Transfer-Encoding: chunked
> Content-Type: text/plain
> 
> And the only thing being done on the PHP side is:
> 
> header("Content-type: ".$blob["mime_type"]);
> header("Content-Disposition: filename=\"$filename\"");
> echo $blob["binary_data"];
> 
> -Jacob
> 
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 

-- 
============================================================================
Neal Rhodes                    MNOP Ltd                       (770) 972-5430
President                  4737 Habersham Ridge         fax:  (770) 978-4741
                          Lilburn (atlanta) GA 30047    

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to send Binary Files Inline?

Posted by Jacob Coby <jc...@listingbook.com>.
> Clearly we need to do SOMETHING else to keep apache happy, but we're
> at a loss to figure out what.  Any ideas?

1) put a space after the colon in the Content-type header
2) take out the attachment clause to Content-Disposition
3) upgrade apache to 1.3.27.  This issue may be a bug and already be
adressed.

We're doing an analagous thing here, but through php.  The returned headers
look like:

HTTP/1.1 200 OK
Date: Wed, 02 Apr 2003 17:28:30 GMT
Server: Apache/1.3.27 (Unix) PHP/4.2.3 mod_ssl/2.8.11 OpenSSL/0.9.6g
X-Powered-By: PHP/4.2.3
X-Accelerated-By: PHPA/1.3.3r1
Content-Disposition: filename="useful.txt"
Transfer-Encoding: chunked
Content-Type: text/plain

And the only thing being done on the PHP side is:

header("Content-type: ".$blob["mime_type"]);
header("Content-Disposition: filename=\"$filename\"");
echo $blob["binary_data"];

-Jacob


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org