mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-21 07:29:37 +01:00
up-storage: make streaming requests without buffering
This commit is contained in:
parent
6b6247b009
commit
f1bb9f83e6
@ -2,7 +2,6 @@ var Error = require('http-errors')
|
||||
var request = require('request')
|
||||
var Stream = require('stream')
|
||||
var URL = require('url')
|
||||
var zlib = require('zlib')
|
||||
var parse_interval = require('./config').parse_interval
|
||||
var Logger = require('./logger')
|
||||
var MyStreams = require('./streams')
|
||||
@ -127,34 +126,13 @@ Storage.prototype.request = function(options, cb) {
|
||||
headers['Content-Type'] = headers['Content-Type'] || 'application/json'
|
||||
}
|
||||
|
||||
var req = request({
|
||||
url : uri,
|
||||
method : method,
|
||||
headers : headers,
|
||||
body : json,
|
||||
ca : this.ca,
|
||||
proxy : this.proxy,
|
||||
encoding : null,
|
||||
timeout : this.timeout,
|
||||
}, function(err, res, body) {
|
||||
var request_callback = cb ? (function (err, res, body) {
|
||||
var error
|
||||
var res_length = err ? 0 : body.length
|
||||
|
||||
do_gunzip(function() {
|
||||
do_decode()
|
||||
do_log()
|
||||
if (cb) cb(err, res, body)
|
||||
})
|
||||
|
||||
function do_gunzip(cb) {
|
||||
if (err) return cb()
|
||||
if (res.headers['content-encoding'] !== 'gzip') return cb()
|
||||
zlib.gunzip(body, function(er, buf) {
|
||||
if (er) err = er
|
||||
body = buf
|
||||
return cb()
|
||||
})
|
||||
}
|
||||
do_decode()
|
||||
do_log()
|
||||
cb(err, res, body)
|
||||
|
||||
function do_decode() {
|
||||
if (err) {
|
||||
@ -196,7 +174,19 @@ Storage.prototype.request = function(options, cb) {
|
||||
}
|
||||
}, message)
|
||||
}
|
||||
})
|
||||
}) : undefined
|
||||
|
||||
var req = request({
|
||||
url : uri,
|
||||
method : method,
|
||||
headers : headers,
|
||||
body : json,
|
||||
ca : this.ca,
|
||||
proxy : this.proxy,
|
||||
encoding : null,
|
||||
gzip : true,
|
||||
timeout : this.timeout,
|
||||
}, request_callback)
|
||||
|
||||
var status_called = false
|
||||
req.on('response', function(res) {
|
||||
@ -204,6 +194,17 @@ Storage.prototype.request = function(options, cb) {
|
||||
status_called = true
|
||||
self.status_check(true)
|
||||
}
|
||||
|
||||
if (!request_callback) {
|
||||
;(function do_log() {
|
||||
var message = '@{!status}, req: \'@{request.method} @{request.url}\' (streaming)'
|
||||
self.logger.warn({
|
||||
request : { method: method, url: uri },
|
||||
level : 35, // http
|
||||
status : res != null ? res.statusCode : 'ERR',
|
||||
}, message)
|
||||
})()
|
||||
}
|
||||
})
|
||||
req.on('error', function(_err) {
|
||||
if (!req._sinopia_aborted && !status_called) {
|
||||
|
Loading…
Reference in New Issue
Block a user