var extend = require('util')._extend

function constructObject(initialObject) {
  initialObject = initialObject || {}

  return {
    extend: function (object) {
      return constructObject(extend(initialObject, object))
    },
    done: function () {
      return initialObject
    }
  }
}

function constructOptionsFrom(uri, options) {
  var params = constructObject()
  if (typeof uri === 'object') params.extend(uri)
  if (typeof uri === 'string') params.extend({uri: uri})
  params.extend(options)
  return params.done()
}

function filterForCallback(values) {
  var callbacks = values.filter(isFunction)
  return callbacks[0]
}

function isFunction(value) {
  return typeof value === 'function'
}

function paramsHaveRequestBody(params) {
  return (
    params.options.body ||
    params.options.requestBodyStream ||
    (params.options.json && typeof params.options.json !== 'boolean') ||
    params.options.multipart
  )
}

exports.isFunction            = isFunction
exports.constructObject       = constructObject
exports.constructOptionsFrom  = constructOptionsFrom
exports.filterForCallback     = filterForCallback
exports.paramsHaveRequestBody = paramsHaveRequestBody

@@ -374,27 +374,31 @@
  if (typeof 
-uri
+options
  === 'object
@@ -399,16 +399,22 @@
 object')
+ %7B%0A   
  params.
@@ -424,14 +424,44 @@
 end(
-uri)%0A 
+options).extend(%7Buri: uri%7D)%0A  %7D else
  if 
@@ -485,16 +485,22 @@
 string')
+ %7B%0A   
  params.
@@ -518,16 +518,29 @@
 : uri%7D)%0A
+  %7D else %7B%0A  
   params
@@ -547,24 +547,24 @@
 .extend(
-options)
+uri)%0A  %7D
 %0A  retur

Fix #1054