This repository has been archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 567
/
queuemessageresult.js
105 lines (87 loc) · 3.18 KB
/
queuemessageresult.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// Copyright (c) Microsoft and contributors. 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.
//
// Module dependencies.
var azureutil = require('azure-common').util;
var RFC1123 = require('azure-common').RFC1123;
var Constants = require('azure-common').Constants;
var HeaderConstants = Constants.HeaderConstants;
exports = module.exports;
exports.parse = function (responseObject) {
var queueMessageResult = {};
queueMessageResult.body = responseObject.body;
if (responseObject.headers[HeaderConstants.BROKER_PROPERTIES_HEADER]) {
queueMessageResult.brokerProperties = {};
var brokerProperties = JSON.parse(responseObject.headers[HeaderConstants.BROKER_PROPERTIES_HEADER]);
Object.keys(brokerProperties).forEach(function (property) {
queueMessageResult.brokerProperties[property] = brokerProperties[property];
});
}
// Process custom properties
var customProperties = null;
for (var header in responseObject.headers) {
// Excluded known standard response headers
if (header !== HeaderConstants.CONTENT_TYPE &&
header !== HeaderConstants.BROKER_PROPERTIES_HEADER &&
header !== HeaderConstants.TRANSFER_ENCODING_HEADER &&
header !== HeaderConstants.SERVER_HEADER &&
header !== HeaderConstants.LOCATION_HEADER &&
header !== HeaderConstants.DATE) {
// Assume custom property
if (!customProperties) {
customProperties = {};
}
customProperties[header] = exports._propertyFromString(responseObject.headers[header]);
}
}
if (responseObject.headers[HeaderConstants.LOCATION_HEADER]) {
queueMessageResult.location = responseObject.headers[HeaderConstants.LOCATION_HEADER];
}
if (responseObject.headers[HeaderConstants.CONTENT_TYPE]) {
queueMessageResult.contentType = responseObject.headers[HeaderConstants.CONTENT_TYPE];
}
if (customProperties) {
queueMessageResult.customProperties = customProperties;
}
return queueMessageResult;
};
exports._propertyFromString = function (value) {
if (value === null) {
return null;
}
if (azureutil.stringStartsWith(value, '\"') && azureutil.stringEndsWith(value, '\"')) {
var text = value.substr(1, value.length - 2);
if (exports.isRFC1123(text)) {
return RFC1123.parse(text);
}
return text;
} else if (value === 'true') {
return true;
} else if (value === 'false') {
return false;
} else if (azureutil.stringIsInt(value)) {
return parseInt(value, 10);
} else {
return parseFloat(value);
}
};
exports.isRFC1123 = function (value) {
if(isNaN(value)) {
var date = new Date(value);
return azureutil.stringIsDate(date);
} else {
return false;
}
};