Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Users

apache adds extra HTML to an error page

 

 

Apache users RSS feed   Index | Next | Previous | View Threaded


rdozijn at hotmail

Jul 9, 2012, 8:04 AM

Post #1 of 4 (271 views)
Permalink
apache adds extra HTML to an error page

hello list,

I am trying to migrate a perl script that acts as a webserver from solaris to linux (red hat). The script is run using apache (httpd) and mod_perl.

It nearly does what it is supposed to, exept for the error pages.
When an error occurs and the script can not fulfill the request, it sends a small error page to the user, containing two p elements, together with status 500.

This used to work OK, but on the new machine, apache decides to add extra text to the page. The receiving application sees a page that does not conform to the specification and thinks it is not an error page. This results in various problems.

I have not the slightest idea in what direction I have to search. Is it an apache configuration issue or maybe a perl library issue? I really don't know.
Can you guys give me some clue?

This is the perl code that makes the error page:

print $cgi->header ( -status => '500 NOT OK',

-type => 'text/html');
print $cgi->start_html ('agent');
print $cgi->p ('ERROR');
print $cgi->p ('error during database lookup');
print $cgi->end_html ();

And this is what I receive in my browser:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

<head>

<title>agent</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</head>

<body><p>ERROR</p>
<p>error during database lookup</p>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html>
<head>

<title>200 OK</title>

</head><body>

<h1>OK</h1>

<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>

<p>Please contact the server administrator,
webmaster [at] sdu and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>

</body>
</html>

thanks in advance, Ruud


margol at beamartyr

Jul 9, 2012, 8:09 AM

Post #2 of 4 (274 views)
Permalink
Re: apache adds extra HTML to an error page [In reply to]

On 09/07/2012 18:04, Ruud Dozijn wrote:
> This used to work OK, but on the new machine, apache decides to add
> extra text to the page. The receiving application sees a page that
> does not conform to the specification and thinks it is not an error
> page. This results in various problems.
This probably isn't actually Apache, but your browser. I remember
dealing with this sort of thing years ago. IIRC, browsers tend to use
default error text unless the custom error page is of a minimum certain
lenght (I think over 1KB). I dealt with it then by padding some extra
bytes to the response.

Hope that helps,
Issac


rdozijn at hotmail

Jul 10, 2012, 1:53 AM

Post #3 of 4 (262 views)
Permalink
RE: apache adds extra HTML to an error page [In reply to]

oops, sent reply to individual user instead of list...

> ------------ Original Message ------------
> > Date: Monday, July 09, 2012 05:04:07 PM +0200
> > From: Ruud Dozijn <rdozijn [at] hotmail>
> > To: users [at] httpd
> > Subject: [users [at] http] apache adds extra HTML to an error page
> >
> >
> > hello list,
> >
> > I am trying to migrate a perl script that acts as a webserver from
> > solaris to linux (red hat). The script is run using apache (httpd)
> > and mod_perl.
> >
> > It nearly does what it is supposed to, exept for the error pages.
> > When an error occurs and the script can not fulfill the request,
> > it sends a small error page to the user, containing two p
> > elements, together with status 500.
> >
> > This used to work OK, but on the new machine, apache decides to
> > add extra text to the page. The receiving application sees a page
> > that does not conform to the specification and thinks it is not an
> > error page. This results in various problems.
> >
> > I have not the slightest idea in what direction I have to search.
> > Is it an apache configuration issue or maybe a perl library issue?
> > I really don't know. Can you guys give me some clue?
> >
> ... snip
>
>
> > thanks in advance, Ruud
> >
>
> You're getting the (apache) server-default error message. You can
> control what is delivered by taking control of the error code in the
> httpd,conf file and/or the error file proper (on RHEL that's
> generally in /var/www/error).
>
> To take control of an error code, uncomment it in the httpd.conf and
> supply an action -- file/script/etc. I think the 404 code has better
> examples in that file than do the 5xx ones.
>
> - Richard

The response I mentioned is indeed made by apache and not by my browser. I have the same result when I do a post request without using a browser.

I think Richard is right about getting a server-default error message.
My first reaction would be to swich off the server-default error message. I don't want the status OR the html to be changed at all.

Is that possible in my local httpd.conf? Where is the behaviour set that gives the extended error message?

I suppose I can supply an empty ErrorDocument in my httpd.conf, but this seems a dirty solution to me.

Moreover, the response I get now is changed from 500 to 200. And that is the primary source of the problems: the receiving process first looks at the status code and parses the html when it is NOT 200. So in the current situation, the receiver thinks everyting is OK due to the changed status code.

Any thoughts?

thanks, Ruud


rdozijn at hotmail

Jul 19, 2012, 1:24 PM

Post #4 of 4 (237 views)
Permalink
RE: apache adds extra HTML to an error page [In reply to]

From: rdozijn [at] hotmail
To: users [at] httpd
Date: Mon, 9 Jul 2012 17:04:07 +0200
Subject: [users [at] http] apache adds extra HTML to an error page


hello list,

I am trying to migrate a perl script that acts as a webserver from solaris to linux (red hat). The script is run using apache (httpd) and mod_perl.

It nearly does what it is supposed to, exept for the error pages.
When an error occurs and the script can not fulfill the request, it sends a small error page to the user, containing two p elements, together with status 500.

This used to work OK, but on the new machine, apache decides to add extra text to the page. The receiving application sees a page that does not conform to the specification and thinks it is not an error page. This results in various problems.

I have not the slightest idea in what direction I have to search. Is it an apache configuration issue or maybe a perl library issue? I really don't know.
Can you guys give me some clue?

This is the perl code that makes the error page:

print $cgi->header ( -status => '500 NOT OK',

-type => 'text/html');
print $cgi->start_html ('agent');
print $cgi->p ('ERROR');
print $cgi->p ('error during database lookup');
print $cgi->end_html ();




I have figured out what was giving me the unwanted results. Maybe someone with similar problems finds this in the archive sometime....

The problem is the perl-CGI library. When switching to another machine, it changed behaviour in a subtle way, causing the problem.
The commands in the code above all print to STDOUT _except for_ the first one, the header routine. This does something indeed: the browser does receive the stated the status code. However, it is not done via STDOUT. Replacing this method call by print statements that make the headerlines, fixed the problem for me:

print "Status: 500 NOT OK\n";
print "Content-type: text/html\n";

phew! Glad I found it at last. Thanks a lot to everyone who took the time to read my questions and helped me!!!

Ruud

Apache users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.