Balamurugan-R / wub

Automatically exported from code.google.com/p/wub
0 stars 0 forks source link

Http NotFound returns a 404 page that is too small, causing some browsers not to render. #34

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
create a File domain, referencing a docroot
start up using chrome, or IE with google toolbar (haven't tested other browsers)
access a page in the file domain that doesn't exist.

What is the expected output? What do you see instead?
you should get a 404 with a page that says
File 'somefile.html' doesn't exist

What version of the product are you using? On what operating system?
svn latest.. 

Please provide any additional information below.

http://www.google.com/support/forum/p/Toolbar/thread?tid=06ca1ad3bf06b621&hl=en
and
http://stackoverflow.com/questions/3970093/include-after-php-404-header-returnin
g-oops-this-link-appears-to-be-broken

mostly seems to bother chrome, but if a 404 has < 512 characters, it will 
display a weird error page.  
This can be fixed by padding the 404 with extra characters.

(the stack overflow page has some nice ascii art that someone uses).

Here is a diff of Utilities/Http.tcl that will pad the content with enough 
spaces so the not default 404 message will work with chrome.

$ svn diff Http.tcl
Index: Http.tcl
===================================================================
--- Http.tcl    (revision 3673)
+++ Http.tcl    (working copy)
@@ -764,6 +764,12 @@
        dict set rsp -code 404
        dict set rsp -rtype NotFound

+       set content_length [string length [dict get $rsp -content]]
+
+       if {$content_length < 512} {
+               dict append rsp -content "\n<!--[string repeat " " [expr {512 - 
$content_length} ]] \n-->"
+       }
+
        return $rsp
     }

Original issue reported on code.google.com by tircnf on 29 Apr 2011 at 7:04

GoogleCodeExporter commented 8 years ago
Added your mods.  Thanks.  What a bizarre thing for chrome to do ...

Original comment by firstros...@gmail.com on 30 Apr 2011 at 1:35

GoogleCodeExporter commented 8 years ago

Original comment by mcc...@gmail.com on 30 Apr 2011 at 2:25

GoogleCodeExporter commented 8 years ago
A line is missing from the patch..

        # Some browsers apparently don't like 404 pages
        # which are too small ... what bizarre behaviour!
        # http://code.google.com/p/wub/issues/detail?id=34
        if {[string length [dict get $rsp -content]] < 512} {
            dict append rsp -content "\n<!--[string repeat " " [expr {512 - $content_length}]] \n-->"
        }

The variable content_length never gets set

Original comment by tircnf on 30 Apr 2011 at 1:37

GoogleCodeExporter commented 8 years ago
content length gets set elsewhere.

Original comment by mcc...@gmail.com on 30 Apr 2011 at 1:54

GoogleCodeExporter commented 8 years ago
I think I tricked you guys with my suggested patch :)

I created a local variable content_length so I wouldn't have to calculate the 
length twice, and used that local variable for both the length check and the 
expression to figure out how many spaces to add.

anyway... if you try and access something in the file domain that doesn't 
exist, wub responds with

Server Error: can't read "content_length": no such variable

can't read "content_length": no such variable
Error Code 'TCL READ VARNAME'

can't read "content_length": no such variable
    while executing
"expr {512 - $content_length}"
    (procedure "::Http::NotFound" line 17)
    invoked from within ....

If you want to check, you can take a clean checkout from svn..
create a docroot/html/

and try and access

http://localhost:8080/html/foo.html

you should get the 404, but you get an error about the missing variable 
"content_length'.

Thanks for the rapid response. 

Original comment by tircnf on 30 Apr 2011 at 2:08

GoogleCodeExporter commented 8 years ago
Sorry, you're right - checked in properly this time.

Original comment by mcc...@gmail.com on 30 Apr 2011 at 2:45