Skip to content

Commit

Permalink
完善file-list的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
leeight committed May 30, 2015
1 parent 1d2f400 commit 546829e
Show file tree
Hide file tree
Showing 97 changed files with 11,364 additions and 12 deletions.
17 changes: 15 additions & 2 deletions src/http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ HttpClient.prototype.sendRequest = function (httpMethod, path, body, headers, pa

// Check the content-length
if (!headers.hasOwnProperty(H.CONTENT_LENGTH)) {
headers[H.CONTENT_LENGTH] = this._guessContentLength(body);
var contentLength = this._guessContentLength(body);
if (!(contentLength === 0 && /GET/i.test(httpMethod))) {
// 如果是 GET 请求,并且 Content-Length 是 0,那么 Request Header 里面就不要出现 Content-Length
// 否则本地计算签名的时候会计算进去,但是浏览器发请求的时候不一定会有,此时导致 Signature Mismatch 的情况
headers[H.CONTENT_LENGTH] = contentLength;
}
}

var client = this;
Expand Down Expand Up @@ -244,7 +249,15 @@ HttpClient.prototype._recvResponse = function (res) {

var payload = [];
/*eslint-disable*/
res.on('data', function (chunk) { payload.push(chunk); });
res.on('data', function (chunk) {
if (Buffer.isBuffer(chunk)) {
payload.push(chunk);
}
else {
// xhr2返回的内容是 string,不是 Buffer,导致 Buffer.concat 的时候报错了
payload.push(new Buffer(chunk));
}
});
res.on('error', function (e) { deferred.reject(e); });
/*eslint-enable*/
res.on('end', function () {
Expand Down
16 changes: 14 additions & 2 deletions test/browser/baidubce-sdk.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5028,7 +5028,12 @@ HttpClient.prototype.sendRequest = function (httpMethod, path, body, headers, pa

// Check the content-length
if (!headers.hasOwnProperty(H.CONTENT_LENGTH)) {
headers[H.CONTENT_LENGTH] = this._guessContentLength(body);
var contentLength = this._guessContentLength(body);
if (!(contentLength === 0 && /GET/i.test(httpMethod))) {
// 如果是 GET 请求,并且 Content-Length 是 0,那么 Request Header 里面就不要出现 Content-Length
// 否则本地计算签名的时候会计算进去,但是浏览器发请求的时候不一定会有,此时导致 Signature Mismatch 的情况
headers[H.CONTENT_LENGTH] = contentLength;
}
}

var client = this;
Expand Down Expand Up @@ -5183,7 +5188,14 @@ HttpClient.prototype._recvResponse = function (res) {

var payload = [];
/*eslint-disable*/
res.on('data', function (chunk) { payload.push(chunk); });
res.on('data', function (chunk) {
if (Buffer.isBuffer(chunk)) {
payload.push(chunk);
}
else {
payload.push(new Buffer(chunk));
}
});
res.on('error', function (e) { deferred.reject(e); });
/*eslint-enable*/
res.on('end', function () {
Expand Down
16 changes: 14 additions & 2 deletions test/browser/demo/dep/baidubce-sdk/0.0.0/baidubce-sdk.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5028,7 +5028,12 @@ HttpClient.prototype.sendRequest = function (httpMethod, path, body, headers, pa

// Check the content-length
if (!headers.hasOwnProperty(H.CONTENT_LENGTH)) {
headers[H.CONTENT_LENGTH] = this._guessContentLength(body);
var contentLength = this._guessContentLength(body);
if (!(contentLength === 0 && /GET/i.test(httpMethod))) {
// 如果是 GET 请求,并且 Content-Length 是 0,那么 Request Header 里面就不要出现 Content-Length
// 否则本地计算签名的时候会计算进去,但是浏览器发请求的时候不一定会有,此时导致 Signature Mismatch 的情况
headers[H.CONTENT_LENGTH] = contentLength;
}
}

var client = this;
Expand Down Expand Up @@ -5183,7 +5188,14 @@ HttpClient.prototype._recvResponse = function (res) {

var payload = [];
/*eslint-disable*/
res.on('data', function (chunk) { payload.push(chunk); });
res.on('data', function (chunk) {
if (Buffer.isBuffer(chunk)) {
payload.push(chunk);
}
else {
payload.push(new Buffer(chunk));
}
});
res.on('error', function (e) { deferred.reject(e); });
/*eslint-enable*/
res.on('end', function () {
Expand Down
Loading

0 comments on commit 546829e

Please sign in to comment.