WIP: initial prototype

- Updated ConnectionPool internals
- Added ConnectionPool.update api
- Experimental: return http response in transform
This commit is contained in:
delvedor
2018-11-08 19:34:12 +01:00
parent c6b8665edd
commit e97f66b0c3
2 changed files with 59 additions and 42 deletions

View File

@ -34,6 +34,7 @@ class Transport {
}
}
// TODO: should be able to send a stream of json data
request (params, callback) {
callback = once(callback)
const result = { body: null, statusCode: null, headers: null, warnings: null }
@ -115,6 +116,13 @@ class Transport {
result.warnings = headers['warning'].split(/(?!\B"[^"]*),(?![^"]*"\B)/)
}
// TODO: expose `asStream` option for returning the
// body already parsed?
if (params.asHttpResponse === true) {
callback(null, response)
return
}
var payload = ''
// collect the payload
response.setEncoding('utf8')
@ -215,9 +223,7 @@ class Transport {
debug('Sniffing ended successfully', body)
const hosts = this.connectionPool.nodesToHost(body.nodes)
this.connectionPool
.empty()
.addConnection(hosts)
this.connectionPool.update(hosts)
callback(null, hosts)
})