« roundup 2006-03-14 | Main | reading the tea-leaves on payment systems »

how IE responds to different HTTP status codes

There is a discussion on intertwingly about feed errors, including the case where a server was serving a valid RSS feed with a 404 (file not found) status code. The feedvalidator was reporting the feed as being non-existent, but IE and firefox would happily display the XML.

I was curious to see how IE handled all the different HTTP status codes, so I put together some ruby scripts to test them.

this is the server: it just listens on port 2000, looks for a 3 digit number in the requested path, and if it finds one returns that number as the HTTP status code in the response, along with a little html page.

require 'webrick'
include WEBrick
s=HTTPServer.new(
 :Port=>2000
)
trap ("INT") {s.shutdown}
s.mount_proc('/') {|req,resp|
     req.path=~/(\d{3})/
     @status=$1?$1:200 
     resp.body="<HTML><body>request:<pre>#{req}</pre>Status:#{@status}<p>#OK#</body></html>"
     resp.status = @status
}
s.start

and this is the client, which uses watir to get IE to call the server, and check the result:

require 'watir'
def test_status(ie,status)
 
 begin
  ie.goto("
http://localhost:2000/#{status}")
  @result=ie.contains_text("#OK")?'OK':'FAIL'
 rescue
  @result='FAIL'
 end
 
 puts "STATUS #{status} -
#{@result}"
end

#list of status codes from http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
#skip 1xx since they causes the client to wait for the server to send a further response
#skip 204 NO CONTENT - watir blocks
#skip 301 / 302  - watir blocks (probably looking for a Location field - according to spec it's not actually mandatory)

ie=Watir::IE.new

%w(
 200 201 202 203 205 206
 300 303 304 305 306 307
 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
 500 501 502 503 504 505
).each {|status| test_status(ie,status)}

ie.close 

Here's the result in IE 6, with 'friendly http errors' disabled ('OK' means that IE rendered the HTML returned, 'FAIL' means IE displayed an error message instead):

STATUS 200 - OK
STATUS 201 - OK
STATUS 202 - OK
STATUS 203 - OK
STATUS 205 - OK
STATUS 206 - OK
STATUS 300 - OK
STATUS 303 - FAIL
STATUS 304 - OK
STATUS 305 - OK
STATUS 306 - OK
STATUS 307 - FAIL
STATUS 400 - OK
STATUS 401 - OK
STATUS 402 - OK
STATUS 403 - OK
STATUS 404 - OK
STATUS 405 - OK
STATUS 406 - OK
STATUS 407 - OK
STATUS 408 - OK
STATUS 409 - OK
STATUS 410 - OK
STATUS 411 - OK
STATUS 412 - OK
STATUS 413 - OK
STATUS 414 - OK
STATUS 415 - OK
STATUS 416 - OK
STATUS 417 - OK
STATUS 500 - OK
STATUS 501 - OK
STATUS 502 - OK
STATUS 503 - OK
STATUS 504 - OK
STATUS 505 - OK

If friendly errors are turned on, this is the result:

STATUS 200 - OK
STATUS 201 - OK
STATUS 202 - OK
STATUS 203 - OK
STATUS 205 - OK
STATUS 206 - OK
STATUS 300 - OK
STATUS 303 - FAIL
STATUS 304 - OK
STATUS 305 - OK
STATUS 306 - OK
STATUS 307 - FAIL
STATUS 400 - FAIL
STATUS 401 - OK
STATUS 402 - OK
STATUS 403 - OK
STATUS 404 - FAIL
STATUS 405 - OK
STATUS 406 - FAIL
STATUS 407 - OK
STATUS 408 - FAIL
STATUS 409 - FAIL
STATUS 410 - OK
STATUS 411 - OK
STATUS 412 - OK
STATUS 413 - OK
STATUS 414 - OK
STATUS 415 - OK
STATUS 416 - OK
STATUS 417 - OK
STATUS 500 - FAIL
STATUS 501 - FAIL
STATUS 502 - OK
STATUS 503 - OK
STATUS 504 - OK
STATUS 505 - FAIL

 

TrackBack

Listed below are links to weblogs that reference how IE responds to different HTTP status codes:

» Browsers and status codes from Sam Ruby
I’ve tried this with Firefox, for which there, sadly, doesn’t appear to be any watir equivalent. Instead, I made do with the following addition: <p><a href='/#{@status.to_i.+1}'>next</a></p> it seems that with Fi [Read More]

» How IE Handles HTTP Status Codes from Ken Schaefer
Jonno Downes (aka Jamtronix) has performed an experiment designed to work out how IE handles various... [Read More]

Comments

I'd be interested to find out if this holds true for SSL requests as well. One longstanding bug seems to be that IE will only show the first 500 or so bytes of an error message delivered using HTTPS.

Christopher, I changed the server code to use SSL by adding "require 'webrick/https'" and then changing the line that instantiates the HTTPServer to this:

s=HTTPServer.new(
:Port=>2000,
:SSLEnable => true,
:SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
:SSLCertName => [ ["C","JP"], ["O","WEBrick.Org"], ["CN", "WWW"] ]
)

then modified the client code to so the url started with https and ran the tests again (IE will throw a warning on the first page complaining it doesn't recognise the cert signing authority - you just need to click 'YES' once).

I got the same results for HTTPS as I did for HTTPS.

I then changed the server to pad the body of the response out to 900 bytes (up from about 400) and ran the tests again. When I did this, the body was displayed for all status codes except 303 and 307 even if 'friendly errors' was turned on. This is consistent with the KB article that Ken (above) links to.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)