Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Own error-page with CGI.pm instead of "Friendly HTTP Error" in Internet-Explorer

by LanX (Bishop)
on Sep 13, 2017 at 16:40 UTC ( #1199334=perlquestion: print w/replies, xml ) Need Help??
LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have problems to show my proper error page inside IE if the status is 4xx or 5xx.

In CB I got the tip to adjust Content-Length (Ambrus++) and indeed there seems to be a relation

The answer is that the serverís response must meet two criteria:

The HTTP Status code must be [400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505] The HTTP Response bodyís byte length must be shorter than a threshold value

If the serverís response meets both criteria, then IE will show its own Friendly HTTP Error page instead of the serverís terse response.

source http://blogs.msdn.microsoft.com/ieinternals/2010/08/18/friendly-http-error-pages/

but adding this doesn't help

print $query->header( -type => 'text/html', -charset => 'utf-8', -status => '400', -Content_Length => '100000', );

I noticed that FF shows the Content-length field of the reply with a lower case "l" no matter how I uppercase the -Content_Length option. (should be the same in IE, but the developer console doesn't help inspecting the header here)

Any suggestions?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re: Own error-page with CGI.pm instead of "Friendly HTTP Error" in Internet-Explorer
by 1nickt (Prior) on Sep 13, 2017 at 20:07 UTC

    CGI error pages in Internet Explorer? Holy 1990s!

    The HTTP Response bodyís byte length must be shorter than a threshold value

    Well, that doesn't mention the Content-Length header, does it? Did you try increasing the size of the "HTTP Response bodyís byte length"?


    The way forward always starts with a minimal test.

      As far as I remember, the stupid "friendly" error pages from MSIE are activated whenever the server returns an HTTP status code indicating an error AND the content of the error document from the server is less than about 1 kByte. Adding a padding HTML comment of about 1 kByte is sufficient to disable this nonsense. Something like this:

      <!-- padding to prevent "friendly" error pages in ancient MSIEs XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXX -->

      Stackoverflow has a nice info box in an answer, quoting Microsoft:

      What makes IE decide to show a friendly error page?

      The answer is that the serverís response must meet two criteria:

      • The HTTP Status code must be 400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505
      • The HTTP Response bodyís byte length must be shorter than a threshold value

      The byte length thresholds are stored in the registry in HKEY_LOCAL_MACHINE under the subkey \SOFTWARE\Microsoft\Internet Explorer\Main\ErrorThresholds.

      • 403, 405, 410: 256 bytes
      • 400, 404, 406, 408, 409, 500, 501, 505: 512 bytes
      • otherwise: 512 bytes

      So, with a padding to at least 1 kByte message body, you should be on the safe side.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      > CGI error pages

      Legacy code. *

      > Internet Explorer?

      Intranet. Default browser.

      > Holy 1990s!

      Yep!

      > Did you try increasing the size of the "HTTP Response bodyís byte length"?

      This did the trick. Thanks!

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      *) CGI.pm is one of the saner parts of the code base...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1199334]
Approved by haukex
Front-paged by haukex
help
Chatterbox?
[1nickt]: Discipulus I was sleeping in :-) It's a Holyday here. No work today. Just eating. Enjoy your day everymonk!

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-11-23 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (336 votes). Check out past polls.

    Notices?