Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rodrigues committed Sep 12, 2012
2 parents b23f517 + 017ae65 commit 3114f23
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
25 changes: 15 additions & 10 deletions lib/services/core/serviceclient.js
Expand Up @@ -180,33 +180,38 @@ ServiceClient.prototype._performRequest = function (webResource, body, options,
self.logger.log(Logger.LogLevels.DEBUG, "FINAL REQUEST OPTIONS:\n" + util.inspect(finalRequestOptions));

var processResponseCallback = function (error, response, responseBody) {

var responseObject;

if (error) {
responseObject = { error: error, response: null };
} else {
if (!(body && body.inputStream)) {
response.body = responseBody;
}

responseObject = self._processResponse(webResource, response);
}

operationCallback(responseObject, next);
};

var requestStream;
if (body && body.outputStream) {
requestStream = request(finalRequestOptions, processResponseCallback);
body.outputStream.pipe(requestStream);
} else {

if (!(body && body.outputStream)) {
finalRequestOptions.body = body.outputData;
requestStream = request(finalRequestOptions, processResponseCallback);
}

if (body && body.inputStream) {
requestStream = request(finalRequestOptions);
requestStream.on('response', function(response) {
processResponseCallback(null, response);
});
requestStream.pipe(body.inputStream);
} else {
requestStream = request(finalRequestOptions, processResponseCallback);
}

if (body && body.outputStream) {
body.outputStream.pipe(requestStream);
}

};

// The filter will do what it needs to the requestOptions and will provide a
Expand Down Expand Up @@ -559,7 +564,7 @@ ServiceClient.isEmulated = function (host) {
* @return {Object} The normalized error object with all properties lower cased.
*/
ServiceClient.prototype._normalizeError = function (error) {
var normalizedError = {};
var normalizedError = new Error();
for (var property in error) {
if (property !== '@') {
if (error[property] && error[property]['#']) {
Expand Down
6 changes: 4 additions & 2 deletions lib/services/table/batchserviceclient.js
Expand Up @@ -96,11 +96,13 @@ BatchServiceClient.prototype.addOperation = function (webResource, outputData) {
outputData = '';
}

if (webResource.httpVerb !== ServiceClient.HTTP_VERB_GET) {
if (webResource.httpVerb !== 'GET') {
webResource.headers[HeaderConstants.CONTENT_ID] = this.operations.length + 1;

if (webResource.httpVerb !== ServiceClient.HTTP_VERB_DELETE) {
if (webResource.httpVerb !== 'DELETE') {
webResource.headers[HeaderConstants.CONTENT_TYPE] = 'application/atom+xml;type=entry';
} else {
delete webResource.headers[HeaderConstants.CONTENT_TYPE];
}

webResource.headers[HeaderConstants.CONTENT_LENGTH] = outputData.length;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
"engines": { "node": ">= 0.6.15" },
"licenses": [ { "type": "Apache", "url": "http://www.apache.org/licenses/LICENSE-2.0" } ],
"dependencies": {
"xml2js" : ">= 0.1.11",
"xml2js" : "0.1.x",
"sax": ">= 0.1.1",
"qs": ">= 0.3.1",
"log": ">= 1.2.0",
Expand Down
35 changes: 35 additions & 0 deletions test/services/core/serviceclient-tests.js
@@ -0,0 +1,35 @@
/**
* Copyright (c) Microsoft. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var should = require('should');
var testutil = require('../../util/util');
var azure = testutil.libRequire('azure');
var ServiceClient = azure.ServiceClient;

suite('serviceclient-tests', function () {
test('NormalizedErrorsAreErrors', function () {
var error = {
'message': 'this is an error message',
'ResultCode': 500,
'somethingElse': 'goes here'
};

var normalizedError = ServiceClient.prototype._normalizeError(error);

normalizedError.should.be.an.instanceOf(Error);
normalizedError.should.have.keys('message', 'resultcode', 'somethingelse');
});
});

1 change: 1 addition & 0 deletions test/testlist.txt
Expand Up @@ -7,6 +7,7 @@ services/blob/sharedaccesssignature-tests.js
services/blob/sharedkey-tests.js
services/blob/sharedkeylite-tests.js
services/blob/filters-tests.js
services/core/serviceclient-tests.js
services/core/exponentialretrypolicyfilter-tests.js
services/core/linearretrypolicyfilter-tests.js
services/queue/queueservice-tests.js
Expand Down

0 comments on commit 3114f23

Please sign in to comment.