Skip to content

Commit

Permalink
修复etag在微信开发工具模拟器及真机中的获取。
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderswang committed Sep 2, 2019
1 parent 14937df commit 6404256
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion demo-album/lib/cos-wx-sdk-v5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/lib/cos-wx-sdk-v5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var request = function (params, callback) {
}
});

requestTask.onHeadersReceived(function(res){
requestTask.onHeadersReceived && requestTask.onHeadersReceived(function(res){
responseHeader = res.header;
});

Expand Down
42 changes: 26 additions & 16 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,9 @@ function headObject(params, callback) {
}
return callback(err);
}
if (data.headers && data.headers.ETag) {
data.ETag = data.headers && data.headers.ETag;
if (data.headers) {
var headers = data.headers;
data.ETag = headers.etag || headers.Etag || headers.ETag || '';
}
callback(null, data);
});
Expand Down Expand Up @@ -1057,8 +1058,10 @@ function getObject(params, callback) {
}
var result = {};
result.Body = data.body;
if (data.headers && data.headers.ETag) {
result.ETag = data.headers && data.headers.ETag;

if (data && data.headers) {
var headers = data.headers;
result.ETag = headers.etag || headers.Etag || headers.ETag || '';
}
util.extend(result, {
statusCode: data.statusCode,
Expand Down Expand Up @@ -1121,7 +1124,11 @@ function putObject(params, callback) {
return callback(err);
}
onProgress({loaded: FileSize, total: FileSize}, true);
if (data && data.headers && data.headers['ETag']) {

if (data && data.headers ) {
var headers = data.headers;
var ETag = headers.etag || headers.Etag || headers.ETag || '';

var url = getUrl({
ForcePathStyle: self.options.ForcePathStyle,
protocol: self.options.Protocol,
Expand All @@ -1133,9 +1140,9 @@ function putObject(params, callback) {
url = url.substr(url.indexOf('://') + 3);
return callback(null, {
Location: url,
ETag: data.headers['ETag'],
ETag: ETag,
statusCode: data.statusCode,
headers: data.headers,
headers: headers,
});
}
callback(null, data);
Expand Down Expand Up @@ -1197,7 +1204,10 @@ function postObject(params, callback) {
if (err) {
return callback(err);
}
if (data && data.headers && data.headers['ETag']) {
if (data && data.headers) {
var headers = data.headers;
var ETag = headers.etag || headers.Etag || headers.ETag || '';

var url = getUrl({
ForcePathStyle: self.options.ForcePathStyle,
protocol: self.options.Protocol,
Expand All @@ -1211,8 +1221,8 @@ function postObject(params, callback) {
return callback(null, {
Location: url,
statusCode: data.statusCode,
headers: data.headers,
ETag: data.headers['ETag'],
headers: headers,
ETag: ETag,
});
}
callback(null, data);
Expand Down Expand Up @@ -1687,12 +1697,12 @@ function multipartUpload(params, callback) {
if (err) {
return callback(err);
}
data['headers'] = data['headers'] || {};
callback(null, {
ETag: data['headers']['ETag'] || '',
statusCode: data.statusCode,
headers: data.headers,
});
if(data && data.headers){
var headers = data.headers;
data.ETag = headers.etag || headers.Etag || headers.ETag || '';
}

callback(null, data);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.7.5';
COS.version = '0.7.6';

module.exports = COS;

0 comments on commit 6404256

Please sign in to comment.