|
1 | 1 | var pkg = require('../package.json'); |
2 | | -var REQUEST = require('cos-request'); |
| 2 | +var REQUEST = require('request'); |
3 | 3 | var mime = require('mime-types'); |
4 | 4 | var Stream = require('stream'); |
5 | 5 | var util = require('./util'); |
@@ -3672,9 +3672,7 @@ function getAuthorizationAsync(params, callback) { |
3672 | 3672 | var headers = util.clone(params.Headers); |
3673 | 3673 | var headerHost = ''; |
3674 | 3674 | util.each(headers, function (v, k) { |
3675 | | - if (v === '') { |
3676 | | - delete headers[k]; |
3677 | | - } |
| 3675 | + (v === '' || ['content-type', 'cache-control'].indexOf(k.toLowerCase()) > -1) && delete headers[k]; |
3678 | 3676 | if (k.toLowerCase() === 'host') headerHost = v; |
3679 | 3677 | }); |
3680 | 3678 |
|
@@ -3993,47 +3991,6 @@ function submitRequest(params, callback) { |
3993 | 3991 | var Query = util.clone(params.qs); |
3994 | 3992 | params.action && (Query[params.action] = ''); |
3995 | 3993 |
|
3996 | | - var contentType; |
3997 | | - var contentLength = 0; |
3998 | | - util.each(params.headers, function (value, key) { |
3999 | | - if (key.toLowerCase() === 'content-type') { |
4000 | | - contentType = value; |
4001 | | - } |
4002 | | - if (key.toLowerCase() === 'content-length') { |
4003 | | - contentLength = value; |
4004 | | - } |
4005 | | - }); |
4006 | | - |
4007 | | - var method = params.method.toLowerCase(); |
4008 | | - var body = params.body; |
4009 | | - if (body) { |
4010 | | - var isStringOrBuffer = typeof body === 'string' || Buffer.isBuffer(body); |
4011 | | - if (!contentLength && isStringOrBuffer) { |
4012 | | - // 传了请求体需补充 content-length |
4013 | | - const buffer = Buffer.from(body, 'utf-8'); |
4014 | | - const contentLength = buffer.length; |
4015 | | - params.headers['Content-Length'] = contentLength; |
4016 | | - } |
4017 | | - } else { |
4018 | | - // 非 get 请求的空请求体需补充 content-length = 0 |
4019 | | - var noContentLengthMethods = ['get'].includes(method); |
4020 | | - if (!noContentLengthMethods) { |
4021 | | - params.headers['Content-Length'] = 0; |
4022 | | - } |
4023 | | - } |
4024 | | - // 上传接口补充默认 content-type |
4025 | | - if (contentType === undefined && body) { |
4026 | | - var defaultContentType = 'application/octet-stream'; |
4027 | | - if (body.type) { |
4028 | | - params.headers['Content-Type'] = body.type; |
4029 | | - } else if (typeof body.pipe === 'function') { |
4030 | | - var isReadStream = body && body.readable && body.path && body.mode; |
4031 | | - params.headers['Content-Type'] = isReadStream ? (mime.lookup(body.path) || defaultContentType) : defaultContentType; |
4032 | | - } else { |
4033 | | - // params.headers['Content-Type'] = defaultContentType; |
4034 | | - } |
4035 | | - } |
4036 | | - |
4037 | 3994 | var SignHost = |
4038 | 3995 | params.SignHost || getSignHost.call(this, { Bucket: params.Bucket, Region: params.Region, Url: params.url }); |
4039 | 3996 | var next = function (tryTimes) { |
@@ -4086,7 +4043,7 @@ function submitRequest(params, callback) { |
4086 | 4043 | networkError, |
4087 | 4044 | }); |
4088 | 4045 | params.SwitchHost = switchHost; |
4089 | | - // 重试时增加请求体 |
| 4046 | + // 重试时增加请求头 |
4090 | 4047 | params.headers['x-cos-sdk-retry'] = true; |
4091 | 4048 | next(tryTimes + 1); |
4092 | 4049 | } else { |
|
0 commit comments