 #
 # It also normalizes all headers by down-casing the header names.
 Resources.mergeHeaders = (request, next)->
-  browser = request.browser
   # Header names are down-cased and over-ride default
   headers =
-    "user-agent":       browser.userAgent
+    "user-agent":       @userAgent
     "accept-encoding":  "identity" # No gzip/deflate support yet
 
   # Merge custom headers from browser first, followed by request.
-  for name, value of browser.headers
+  for name, value of @headers
     headers[name.toLowerCase()] = value
   if request.headers
     for name, value of request.headers

#
# Filters used before the request take two arguments.  Filters used with the
# response take three arguments.
Resources.addFilter = (filter)->
  assert filter.call, "Filter must be a function"
  assert filter.length == 2 || filter.length == 3, "Filter function takes 2 (before filter) or 3 (after filter) arguments"

  headers.host = host

  # Apply authentication credentials
  if credentials = @authenticate(host, false)
    credentials.apply(headers)

  request.headers = headers
