Patch neo4j lib

This commit is contained in:
Anatoliy Chakkaev 2011-10-16 21:24:54 +04:00
parent f799e80fbb
commit f8b1b87a65
2 changed files with 29 additions and 1 deletions

View File

@ -7,6 +7,27 @@
status = require 'http-status'
request = require 'request'
applyPatch = (method, auth) ->
return if applyPatch.patched[method]
applyPatch.patched[method] = true
__m = request[method]
request[method] = ->
args = [].slice.call(arguments)
url = args[0]
# console.log(args)
if typeof url == 'string' && !url.match(/https?:\/\/[^\/]*@/)
args[0] = url.replace(/http:\/\//, 'http://' + auth + '@')
# normalize opts
if url && url.url
url.uri = url.url
delete url.url
# handle auth in uri
if url && url.uri && url.uri.match && !url.uri.match(/https?:\/\/[^\/]*@/)
args[0].uri = url.uri.replace(/http:\/\//, 'http://' + auth + '@')
__m.apply(request, args)
applyPatch.patched = {}
util = require './util_'
adjustError = util.adjustError
@ -15,7 +36,15 @@ Node = require './Node_'
module.exports = class GraphDatabase
constructor: (url) ->
@url = url
@auth = require('url').parse(url).auth
applyPatch('get', @auth)
applyPatch('post', @auth)
applyPatch('put', @auth)
applyPatch('del', @auth)
applyPatch('head', @auth)
# Cache
@_root = null

View File

@ -15,7 +15,6 @@
},
"dependencies": {
"redis": ">= 0.6.7",
"neo4j": ">= 0.2.1",
"mongoose": ">= 2.2.3"
},
"devDependencies": {}