 # jQuery.ajaxSettings.xhr was breaking regular IE7 loading. Better to localize
 # this anyway to solve that problem and loading order issues.
 hackAroundFirefoxXhrHeadersBug = ->
+  console?.log "Hacking AJAX response headers for Firefox"
+  XHR_HEADERS = [
+    "Cache-Control", "Content-Language", "Content-Type"
+    "Expires", "Last-Modified", "Pragma"
+  ]
   xhr = jQuery.ajaxSettings.xhr()
   originalFun = xhr.getAllResponseHeaders
   xhr.getAllResponseHeaders = ->
-    XHR_HEADERS = [
-      "Cache-Control", "Content-Language", "Content-Type"
-      "Expires", "Last-Modified", "Pragma"
-    ]
-    return allHeaders if (allHeaders = originalFun.call xhr)?
+    return allHeaders if allHeaders = originalFun.call xhr
     lines = for name in XHR_HEADERS when xhr.getResponseHeader(name)?
       "#{name}: #{xhr.getResponseHeader name}"
     lines.join '\n'

# This code was shamelessly stolen from:
# https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js
if $.browser.msie and parseInt($.browser.version, 10) in [8, 9]
  jQuery.ajaxTransport (s) ->
    if s.crossDomain and s.async
      if s.timeout

    console?.log "_success", arguments
    @_open data
    return if @_stopRequestLoop
    console?.log "status #{jqXhr.status}"
    if jqXhr.status == 204
      # If we get a 204 back, that means the server timed-out and sent back a 204 with a
      # X-Http-Next-Request header
      #
      # Why did we use a 204 and not a 408? Because Firefox is really stupid about 400 level error
      # codes and would claims its a 0 error code, which we use for something else. Firefox is IE
      # in this case
      @connect(@_okInterval)
