Loading ...
Sorry, an error occurred while loading the content.

Re[2]: GIF contents not "coming out"

Expand Messages
  • Chris Drake
    Hi Stas, Thanks for the pointers. I ve spent another hour on the problem, and found that this fixes it:- print Content-type: image/gif r n r n ; local $| =
    Message 1 of 9 , Jan 23, 2004
    • 0 Attachment
      Hi Stas,

      Thanks for the pointers. I've spent another hour on the problem, and
      found that this fixes it:-

      print "Content-type: image/gif\r\n\r\n"; local $| = 1; print "";

      (interestingly, omitting the empty print causes the problem to come
      back);

      This only happens with GIF data incidentally - sending text worked
      fine before now.

      Thanks also for the efficiency tip. Reading up on the meaning of "$/"
      I find that it's on page 666 of the perl bible - is this an omen?

      Sorry I didn't follow the bug procedure - the mod_perl site has
      altogether way too much information, and as I'm in a production
      environment with (as usual) unreasonable timeframes to get stuff
      working laden upon me, I missed that bit :-)

      I'm guessing that most people only want to send HTML or graphics out
      using mod_perl, so maybe a small extra manual section "EXAMPLES" with
      suggested skeleton code to accomplish this would be a great idea
      (especially for busy people like me)?

      Grr. My ADSL went down, so please excuse the missing "mybugreport"
      stuff. Incidentally - ModPerl 2.0 is part of RedHat ES 3.0 - but
      there is no "mybugreport" file anyplace on my system...

      Kind Regards,
      Chris Drake


      Saturday, January 24, 2004, 1:25:43 PM, you wrote:

      SB> Chris Drake wrote:
      >> Hi All,
      >>
      >> My mod_perl 2 script is not sending back the contents of the GIF I'm
      >> trying to print. Running it locally, it does, or if I go:-
      >> print "foo";
      >> ... I get "foo" - but when I print the GIF - I just get back the
      >> headers without any content!!!

      SB> Please read on how we like problems to be reported: http://perl.apache.org/bugs/

      SB> Make sure to include the relevant config section (is it 'perl-script' or
      SB> 'modperl' SetHandler?)

      SB> Also any difference if you remove 'use bytes'?

      SB> Also this is much more efficient way to read/print a multiline file:

      SB> local $/;
      SB> $::r->print(<GIF>);

      SB> __________________________________________________________________
      SB> Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
      SB> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
      SB> mailto:stas@... http://use.perl.org http://apacheweek.com
      SB> http://modperlbook.org http://apache.org http://ticketmaster.com


      --
      Reporting bugs: http://perl.apache.org/bugs/
      Mail list info: http://perl.apache.org/maillist/modperl.html
      List etiquette: http://perl.apache.org/maillist/email-etiquette.html
    • Ged Haywood
      Hi there, ... Wrong beast. My copy of the Camel Book only goes up to page 645. ... You can t expect the contributors to the mod_perl List to make up for your
      Message 2 of 9 , Jan 24, 2004
      • 0 Attachment
        Hi there,

        On Sat, 24 Jan 2004, Chris Drake wrote:

        > Reading up on the meaning of "$/" I find that it's on page 666 of
        > the perl bible - is this an omen?

        Wrong beast. My copy of the Camel Book only goes up to page 645.

        > maybe a small extra manual section "EXAMPLES" ...
        > (especially for busy people like me)?

        You can't expect the contributors to the mod_perl List to make up for
        your lack of effort in the study department. If you're to do the best
        job that you can then you must take the time to research the subject.

        There's a LARGE set of examples called the "Perl Cookbook" and I can
        assure you that the people who wrote it were kept very busy indeed
        by their effort.

        73,
        Ged.




        --
        Reporting bugs: http://perl.apache.org/bugs/
        Mail list info: http://perl.apache.org/maillist/modperl.html
        List etiquette: http://perl.apache.org/maillist/email-etiquette.html
      • semuel
        Hello There. If you want to eliminate the need of the print line, you should reverse the order of the commands: local $| = 1; print Content-type:
        Message 3 of 9 , Jan 24, 2004
        • 0 Attachment
          Hello There.

          If you want to eliminate the need of the 'print ""' line, you should reverse
          the order of the commands:
          local $| = 1; print "Content-type: image/gif\r\n\r\n";
          (That's because the $| is a flashing command. NM)
          And you don't need to "\r\n\r\n". "\n\n" will do the job.

          Semuel.

          -----Original Message-----
          From: Chris Drake [mailto:christopher@...]
          Sent: Saturday, January 24, 2004 6:07 AM
          To: modperl@...
          Subject: Re[2]: GIF contents not "coming out"

          Hi Stas,

          Thanks for the pointers. I've spent another hour on the problem, and
          found that this fixes it:-

          print "Content-type: image/gif\r\n\r\n"; local $| = 1; print "";

          (interestingly, omitting the empty print causes the problem to come
          back);

          This only happens with GIF data incidentally - sending text worked
          fine before now.


          Kind Regards,
          Chris Drake


          Saturday, January 24, 2004, 1:25:43 PM, you wrote:

          SB> Chris Drake wrote:
          >> Hi All,
          >>
          >> My mod_perl 2 script is not sending back the contents of the GIF I'm
          >> trying to print. Running it locally, it does, or if I go:-
          >> print "foo";
          >> ... I get "foo" - but when I print the GIF - I just get back the
          >> headers without any content!!!

          SB> Please read on how we like problems to be reported:
          http://perl.apache.org/bugs/

          SB> Make sure to include the relevant config section (is it 'perl-script' or

          SB> 'modperl' SetHandler?)

          SB> Also any difference if you remove 'use bytes'?

          SB> Also this is much more efficient way to read/print a multiline file:

          SB> local $/;
          SB> $::r->print(<GIF>);





          --
          Reporting bugs: http://perl.apache.org/bugs/
          Mail list info: http://perl.apache.org/maillist/modperl.html
          List etiquette: http://perl.apache.org/maillist/email-etiquette.html
        • Ged Haywood
          Hello there, ... According to the standard you should send both r and n. It is bad practice to play fast and loose with standards.
          Message 4 of 9 , Jan 24, 2004
          • 0 Attachment
            Hello there,

            On Sat, 24 Jan 2004, semuel wrote:

            > you don't need to "\r\n\r\n". "\n\n" will do the job.

            According to the standard you should send both \r and \n.
            It is bad practice to play fast and loose with standards.

            http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html

            73,
            Ged.



            --
            Reporting bugs: http://perl.apache.org/bugs/
            Mail list info: http://perl.apache.org/maillist/modperl.html
            List etiquette: http://perl.apache.org/maillist/email-etiquette.html
          • Stas Bekman
            ... Not if you use Apache. It does the right thing with n n for you, because it parses your headers and strips n n anyway, adding other HTTP headers and
            Message 5 of 9 , Jan 24, 2004
            • 0 Attachment
              Ged Haywood wrote:
              > Hello there,
              >
              > On Sat, 24 Jan 2004, semuel wrote:
              >
              >
              >>you don't need to "\r\n\r\n". "\n\n" will do the job.
              >
              >
              > According to the standard you should send both \r and \n.
              > It is bad practice to play fast and loose with standards.
              >
              > http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html

              Not if you use Apache. It does the right thing with "\n\n" for you, because it
              parses your headers and strips "\n\n" anyway, adding other HTTP headers and
              terminating each with "\r\n".

              Of course if you use non-parsed-headers scripts/handlers, then you are on your
              own to do the right things.

              __________________________________________________________________
              Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
              http://stason.org/ mod_perl Guide ---> http://perl.apache.org
              mailto:stas@... http://use.perl.org http://apacheweek.com
              http://modperlbook.org http://apache.org http://ticketmaster.com


              --
              Reporting bugs: http://perl.apache.org/bugs/
              Mail list info: http://perl.apache.org/maillist/modperl.html
              List etiquette: http://perl.apache.org/maillist/email-etiquette.html
            • Chris Drake
              s If you want to eliminate the need of the print line, you should reverse s the order of the commands: s local $| = 1; print Content-type:
              Message 6 of 9 , Jan 24, 2004
              • 0 Attachment
                s> If you want to eliminate the need of the 'print ""' line, you should reverse
                s> the order of the commands:
                s> local $| = 1; print "Content-type: image/gif\r\n\r\n";

                No, that doesn't work - I forget the exact error - something about
                "script did not send headers" I think.

                Kind Regards,
                Chris Drake


                --
                Reporting bugs: http://perl.apache.org/bugs/
                Mail list info: http://perl.apache.org/maillist/modperl.html
                List etiquette: http://perl.apache.org/maillist/email-etiquette.html
              • Xavier Noria
                ... Looks like handling n is required in CGI 1.1[*] if the script is not using NPH: * On the one hand in section 7.2.1.1 we have Content-Type =
                Message 7 of 9 , Jan 24, 2004
                • 0 Attachment
                  On Jan 25, 2004, at 0:05, Stas Bekman wrote:

                  > Ged Haywood wrote:
                  >> Hello there,
                  >> On Sat, 24 Jan 2004, semuel wrote:
                  >>> you don't need to "\r\n\r\n". "\n\n" will do the job.
                  >> According to the standard you should send both \r and \n.
                  >> It is bad practice to play fast and loose with standards.
                  >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
                  >
                  > Not if you use Apache. It does the right thing with "\n\n" for you,
                  > because it parses your headers and strips "\n\n" anyway, adding other
                  > HTTP headers and terminating each with "\r\n".

                  Looks like handling "\n" is required in CGI 1.1[*] if the script is not
                  using NPH:

                  * On the one hand in section 7.2.1.1 we have

                  Content-Type = "Content-Type" ":" media-type NL

                  and NL is defined as CR | LF. In my understanding that makes "\r\n"
                  illegal indeed!

                  * On the other hand section 7.2.2 says "Servers MUST resolve conflicts
                  beteen CGI header and HTTP header formats or names (see section 8)."
                  Which might have as a side effect the fact that "\r\n" ends up working
                  in practice.

                  -- fxn

                  [*] http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html


                  --
                  Reporting bugs: http://perl.apache.org/bugs/
                  Mail list info: http://perl.apache.org/maillist/modperl.html
                  List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                • Stas Bekman
                  ... I must correct myself and say that I didn t check whether it actually sends r n or n or r . What I was trying to say is that since it re-parses
                  Message 8 of 9 , Jan 24, 2004
                  • 0 Attachment
                    Xavier Noria wrote:
                    > On Jan 25, 2004, at 0:05, Stas Bekman wrote:
                    >
                    >> Ged Haywood wrote:
                    >>
                    >>> Hello there,
                    >>> On Sat, 24 Jan 2004, semuel wrote:
                    >>>
                    >>>> you don't need to "\r\n\r\n". "\n\n" will do the job.
                    >>>
                    >>> According to the standard you should send both \r and \n.
                    >>> It is bad practice to play fast and loose with standards.
                    >>> http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
                    >>
                    >>
                    >> Not if you use Apache. It does the right thing with "\n\n" for you,
                    >> because it parses your headers and strips "\n\n" anyway, adding other
                    >> HTTP headers and terminating each with "\r\n".

                    I must correct myself and say that I didn't check whether it actually sends
                    "\r\n" or "\n" or "\r". What I was trying to say is that since it re-parses
                    your headers (in a non-nph mode) it'll do the right thing...

                    __________________________________________________________________
                    Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
                    http://stason.org/ mod_perl Guide ---> http://perl.apache.org
                    mailto:stas@... http://use.perl.org http://apacheweek.com
                    http://modperlbook.org http://apache.org http://ticketmaster.com


                    --
                    Reporting bugs: http://perl.apache.org/bugs/
                    Mail list info: http://perl.apache.org/maillist/modperl.html
                    List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                  • Stas Bekman
                    ... can you please send me (off-list) an image that you have the problem with? Or is it with any image at all? ... I suppose that your ADSL is still down,
                    Message 9 of 9 , Feb 2, 2004
                    • 0 Attachment
                      Chris Drake wrote:
                      > Hi Stas,
                      >
                      > Thanks for the pointers. I've spent another hour on the problem, and
                      > found that this fixes it:-
                      >
                      > print "Content-type: image/gif\r\n\r\n"; local $| = 1; print "";
                      >
                      > (interestingly, omitting the empty print causes the problem to come
                      > back);
                      >
                      > This only happens with GIF data incidentally - sending text worked
                      > fine before now.

                      can you please send me (off-list) an image that you have the problem with? Or
                      is it with any image at all?

                      > Sorry I didn't follow the bug procedure - the mod_perl site has
                      > altogether way too much information, and as I'm in a production
                      > environment with (as usual) unreasonable timeframes to get stuff
                      > working laden upon me, I missed that bit :-)
                      >
                      > I'm guessing that most people only want to send HTML or graphics out
                      > using mod_perl, so maybe a small extra manual section "EXAMPLES" with
                      > suggested skeleton code to accomplish this would be a great idea
                      > (especially for busy people like me)?
                      >
                      > Grr. My ADSL went down, so please excuse the missing "mybugreport"
                      > stuff. Incidentally - ModPerl 2.0 is part of RedHat ES 3.0 - but
                      > there is no "mybugreport" file anyplace on my system...

                      I suppose that your ADSL is still down, since you've never sent in the details
                      I've asked for, Chris. I was trying to reproduce your problem but without
                      seeing your configuration and the rest of things I don't know about, I can't
                      reproduce it and therefore fix it.

                      You load 'use Chris', which you didn't show what it does. I suspect that some
                      code that you use is changing the value of $| to 1, w/o localizing it, which
                      affects your script's header sending section:

                      print "Content-type: image/gif\n"; print "\n";

                      which if my guess is correct, becomes:

                      local $| = 1;
                      print "Content-type: image/gif\n"; print "\n";

                      the first print sends out an incomplete header, and the thing obviously breaks.

                      Also I'm not sure why do you mix, print and $r->print.

                      I wrote the test which looks like this:

                      use strict;
                      use warnings FATAL => 'all';

                      use Apache::RequestIO ();
                      use Apache::RequestRec ();

                      my $r = shift;
                      $r->content_type('image/gif');

                      my $image_path = "whatever.gif";
                      open my $fh, $image_path or die "Can't open $image_path: $!";
                      local $/;
                      $r->print(<$fh>);
                      close $fh;

                      it works just fine for me and it'll work correctly no matter what's the value
                      of $|, since it sets the header via the content_type API and not printing it.
                      The configuration it's running under is:

                      Alias /registry/
                      /home/stas/apache.org/modperl-2.0/ModPerl-Registry/t/cgi-bin/
                      PerlModule ModPerl::Registry
                      <Location /registry>
                      SetHandler perl-script
                      Options +ExecCGI
                      PerlResponseHandler ModPerl::Registry
                      PerlOptions +ParseHeaders
                      </Location>


                      __________________________________________________________________
                      Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
                      http://stason.org/ mod_perl Guide ---> http://perl.apache.org
                      mailto:stas@... http://use.perl.org http://apacheweek.com
                      http://modperlbook.org http://apache.org http://ticketmaster.com

                      --
                      Reporting bugs: http://perl.apache.org/bugs/
                      Mail list info: http://perl.apache.org/maillist/modperl.html
                      List etiquette: http://perl.apache.org/maillist/email-etiquette.html
                    Your message has been successfully submitted and would be delivered to recipients shortly.