CGI.PM not setting HTTP header

Discussion in 'Perl Misc' started by Mark, Nov 25, 2004.

  1. Mark

    Mark Guest

    My Perl CGI script is producing valid HTML (as far as I can tell,)
    but the server is returning a MIME type of 'text/plain'. I have tried
    using the CGI.PM module to set the MIME type in the header,
    but this merely adds a _second_ header to the output stream,
    and this second header ends up displaying as text in the browser
    window! The actual HTTp header is unaffected, still returning the
    'text/plain' MIME type.

    Any suggestions?

    Thanks
    -Mark
    Mark, Nov 25, 2004
    #1
    1. Advertising

  2. Mark

    Tore Aursand Guest

    On Wed, 24 Nov 2004 21:12:45 -0800, Mark wrote:
    > My Perl CGI script is producing valid HTML (as far as I can tell,)
    > but the server is returning a MIME type of 'text/plain'.

    ^^^^^^^^^^

    Is the server written in Perl?


    --
    Tore Aursand <>
    "A car is not the only thing that can be recalled by its maker."
    (Unknown)
    Tore Aursand, Nov 25, 2004
    #2
    1. Advertising

  3. Mark

    John Bokma Guest

    Mark wrote:

    > My Perl CGI script is producing valid HTML (as far as I can tell,)


    Don't tell, check. Run your script from the CLI, or connect to the
    webserver using telnet port 80. Nowadays you often have to include a host
    header when you use telnet (since many virtual hosts share one ip)

    > but the server is returning a MIME type of 'text/plain'.


    Uhmmm... maybe the server is confused about the default "XHTML" header?

    > I have tried
    > using the CGI.PM module to set the MIME type in the header,
    > but this merely adds a _second_ header to the output stream,
    > and this second header ends up displaying as text in the browser
    > window! The actual HTTp header is unaffected, still returning the
    > 'text/plain' MIME type.
    >
    > Any suggestions?


    Reduce your script to the bare minimum that shows this result, and post it
    (in this thread, don't start a new one)

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Nov 25, 2004
    #3
  4. Mark

    Alan Mead Guest

    On Wed, 24 Nov 2004 21:12:45 -0800, Mark wrote:

    > My Perl CGI script is producing valid HTML (as far as I can tell,)
    > but the server is returning a MIME type of 'text/plain'. I have tried
    > using the CGI.PM module to set the MIME type in the header,
    > but this merely adds a _second_ header to the output stream,
    > and this second header ends up displaying as text in the browser
    > window! The actual HTTp header is unaffected, still returning the
    > 'text/plain' MIME type.


    Well, here's a stupid question: Is the very first thing you print the
    CGI.pm function "header"? If you have a complicated script, you can test
    this by printing header near the top.

    I've had weird results using IE (and less often Netscape) to browse the
    results of web applications. The browser would think it's an XML
    document and then complain that it's broken. I don't recall what went
    wrong, but it was always a bug in my script that I was able to find.

    Or if you're saying that even the most basic CGI script always gets
    returned as plain text then I guess you're having an apache/iis/whatever
    issue, not a Perl issue.

    -Alan
    Alan Mead, Nov 25, 2004
    #4
  5. Mark

    Mark Guest

    Thanks to everyone who replied. It appears that Alan was on the
    right track. My CGI script is implemented in two separate modules,
    and each module creates a new CGI object. I was setting the header
    from the second instance, which was streamed after whatever
    default header was being produced by the _first_ instance.

    I added my header code to the first instance, and now everything
    works fine.

    So. . .it appears that the web server will output an HTTP header
    for each instance of a CGI object that I create? Is there any way
    to create a CGI object _without_ producing an HTTP header?
    I am using CGI in my first module simply to parse the URL.
    I would prefer not to produce any output from the first module,
    although I suppose I can live with it.

    Thanks
    -Mark
    Mark, Nov 25, 2004
    #5
  6. Mark

    Mark Guest

    "Tore Aursand" <> wrote:
    >
    > Is the server written in Perl?


    It's an Apache server.
    Mark, Nov 25, 2004
    #6
  7. On Thu, 25 Nov 2004, Mark wrote:

    > So. . .it appears that the web server will output an HTTP header
    > for each instance of a CGI object that I create? Is there any way
    > to create a CGI object _without_ producing an HTTP header?


    I feel sure you're looking at this from the wrong end. The idea of
    the CGI.pm object is that it handles the CGI request/response
    transaction. Each invocation of a CGI script will handle one
    request/response transaction (that's the way that CGI scripts work in
    general, it's not in any way special to CGI.pm), and, as such, needs
    one CGI object which will carry the transaction through from
    invocation to completion.

    It's only in specialised uses of CGI.pm that one would ever use more
    than one CGI object, and I see no reason to think that you're dealing
    with such a specialised requirement from your description.

    > I am using CGI in my first module simply to parse the URL.
    > I would prefer not to produce any output from the first module,
    > although I suppose I can live with it.


    We haven't see any code yet; but my hunch is that what you really need
    your script to do is to hand the same CGI object around to the various
    parts which use it.

    hope this helps
    Alan J. Flavell, Nov 25, 2004
    #7
  8. Mark

    Mark Guest

    "Alan J. Flavell" <> wrote:
    > On Thu, 25 Nov 2004, Mark wrote:
    >
    > We haven't see any code yet; but my hunch is that what you really need
    > your script to do is to hand the same CGI object around to the various
    > parts which use it.


    Yep. I solved the problem by using only one CGI object.
    No doubt I can refine it a bit more, but it works for now.
    Thanks again for your help.

    -Mark
    Mark, Nov 25, 2004
    #8
  9. Mark <> wrote:
    > "Tore Aursand" <> wrote:
    >>
    >> Is the server written in Perl?

    >
    > It's an Apache server.



    Is the Apache server written in Perl?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 25, 2004
    #9
  10. Mark

    Mark Guest

    "Tad McClellan" <> wrote:

    > Is the Apache server written in Perl?


    Maybe.
    Mark, Nov 25, 2004
    #10
  11. On Thu, 25 Nov 2004, Mark wrote:

    > "Tad McClellan" <> wrote:
    >
    > > Is the Apache server written in Perl?

    >
    > Maybe.


    Watch out. The hon Usenauts are trying to advise you, in their
    somewhat grumpy and obtuse fashion, that you started off by saying

    || but the server is returning a MIME type of 'text/plain'.

    If you truly had a web server problem, then your problem would be
    wildly off-topic here. I think they want you to acknowledge that.

    As it turned out, you've solved your problem by using CGI.pm better.
    It's still not (quite) a Perl language problem, and might have been
    more at home on a usenet group that's primarily about the CGI, but
    you've rubbed-up several of the respected contributors here in the
    wrong way, and I wouldn't really recommend that: they may prove
    infinitely helpful to you in future, if you give them the idea that
    you're keen to learn.

    all the best
    Alan J. Flavell, Nov 25, 2004
    #11
  12. Mark <> wrote:
    > "Tad McClellan" <> wrote:
    >
    >> Is the Apache server written in Perl?

    >
    > Maybe.



    *plonk*


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 26, 2004
    #12
  13. Mark

    Tore Aursand Guest

    On Thu, 25 Nov 2004 09:47:48 -0800, Mark wrote:
    >> Is the server written in Perl?


    > It's an Apache server.


    ....and Apache, last time I checked, is not written in Perl. Your problem,
    as you describe it, is that the _web server_ (Apache) is not sending the
    correct header(s) to the client.

    Thus, this isn't a Perl problem at all. At least you haven't showed us
    the _Perl relevant_ information to make it a Perl problem.

    I'm not emphasizing this just to be rude or something, but sometimes (ie.
    always) it's smarter to post a question in the most relevant newsgroups.


    --
    Tore Aursand <>
    "What we do is never understood, but only praised and blamed."
    (Friedrich Nietzsche)
    Tore Aursand, Nov 26, 2004
    #13
  14. Mark

    Mark Guest

    "Alan J. Flavell" <> wrote

    > As it turned out, you've solved your problem by using CGI.pm better.
    > It's still not (quite) a Perl language problem, and might have been
    > more at home on a usenet group that's primarily about the CGI, but
    > you've rubbed-up several of the respected contributors here in the
    > wrong way, and I wouldn't really recommend that: they may prove
    > infinitely helpful to you in future, if you give them the idea that
    > you're keen to learn.


    I certainly do not believe that I said or did anything even remotely
    offensive.
    Mark, Nov 26, 2004
    #14
  15. Mark

    Alan Mead Guest

    On Thu, 25 Nov 2004 08:41:34 -0800, Mark wrote:

    > So. . .it appears that the web server will output an HTTP header
    > for each instance of a CGI object that I create? Is there any way


    No, I think the server adds something but it doesn't print the
    headers. It's up to you to print an appropriate header (usually
    "print header" after importing the CGI shortcuts) once for each
    HTML page that you create.

    You might wonder why? Well, headers are also the way you transmit cookies
    and do things like redirect. So you want to control them in your program
    rather than have the server do it... or automatically by CGI.pm.

    -Alan
    Alan Mead, Nov 26, 2004
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek Basch

    CGI and HTTP Header Location redirects

    Derek Basch, Feb 4, 2005, in forum: Python
    Replies:
    1
    Views:
    524
    Paul Rubin
    Feb 4, 2005
  2. Derek Basch
    Replies:
    0
    Views:
    335
    Derek Basch
    Feb 4, 2005
  3. Derek Basch
    Replies:
    1
    Views:
    302
    Paul Rubin
    Feb 5, 2005
  4. mlt
    Replies:
    2
    Views:
    832
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Eric

    Setting HTTP Header Attributes

    Eric, Aug 23, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    132
    Tim Gallivan
    Aug 25, 2004
Loading...

Share This Page