@ohos-ports/core 1.0.113-beta.0 → 1.16.33-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +3 -0
- package/lib/api/node.js +176 -0
- package/lib/api/team.js +1889 -0
- package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
- package/lib/blocklet/downloader/bundle-downloader.js +316 -0
- package/lib/blocklet/downloader/constants.js +3 -0
- package/lib/blocklet/downloader/resolve-download.js +187 -0
- package/lib/blocklet/extras.js +177 -0
- package/lib/blocklet/hooks.js +89 -0
- package/lib/blocklet/manager/base.js +49 -0
- package/lib/blocklet/manager/config-synchronizer.js +128 -0
- package/lib/blocklet/manager/disk.js +5170 -0
- package/lib/blocklet/manager/engine.js +124 -0
- package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
- package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
- package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
- package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
- package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
- package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
- package/lib/blocklet/manager/pm2-events.js +50 -0
- package/lib/blocklet/migration-dist/migration.cjs +38605 -0
- package/lib/blocklet/migration-dist/run-script.cjs +29 -0
- package/lib/blocklet/migration.js +145 -0
- package/lib/blocklet/project/connect-by-studio.js +91 -0
- package/lib/blocklet/project/connect-to-store.js +64 -0
- package/lib/blocklet/project/create-pack-release.js +293 -0
- package/lib/blocklet/project/disconnect-from-store.js +13 -0
- package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
- package/lib/blocklet/project/index.js +545 -0
- package/lib/blocklet/project/logo.png +0 -0
- package/lib/blocklet/project/publish-to-store.js +108 -0
- package/lib/blocklet/project/util.js +194 -0
- package/lib/blocklet/security/access-policy.js +131 -0
- package/lib/blocklet/security/index.js +309 -0
- package/lib/blocklet/security/response-header-policy.js +178 -0
- package/lib/blocklet/security/security-rule.js +127 -0
- package/lib/blocklet/security/utils.js +35 -0
- package/lib/blocklet/security/validator.js +40 -0
- package/lib/blocklet/storage/backup/base.js +149 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
- package/lib/blocklet/storage/backup/blocklet.js +159 -0
- package/lib/blocklet/storage/backup/blocklets.js +109 -0
- package/lib/blocklet/storage/backup/data.js +35 -0
- package/lib/blocklet/storage/backup/disk.js +131 -0
- package/lib/blocklet/storage/backup/logs.js +24 -0
- package/lib/blocklet/storage/backup/routing-rule.js +47 -0
- package/lib/blocklet/storage/backup/spaces.js +345 -0
- package/lib/blocklet/storage/restore/base.js +74 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
- package/lib/blocklet/storage/restore/blocklet.js +56 -0
- package/lib/blocklet/storage/restore/blocklets.js +43 -0
- package/lib/blocklet/storage/restore/disk.js +104 -0
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +174 -0
- package/lib/blocklet/storage/utils/disk.js +178 -0
- package/lib/blocklet/storage/utils/hash.js +53 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/cert.js +221 -0
- package/lib/crons/check-new-version.js +68 -0
- package/lib/crons/monitor-disk-usage.js +46 -0
- package/lib/crons/rotate-pm2-logs/index.js +41 -0
- package/lib/crons/rotate-pm2-logs/script.js +56 -0
- package/lib/event/auto-backup-handler.js +48 -0
- package/lib/event/index.js +520 -0
- package/lib/index.js +768 -364
- package/lib/locales/ar.js +18 -0
- package/lib/locales/de.js +21 -0
- package/lib/locales/en.js +19 -0
- package/lib/locales/es.js +21 -0
- package/lib/locales/fr.js +21 -0
- package/lib/locales/hi.js +18 -0
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +20 -0
- package/lib/locales/index.js +54 -0
- package/lib/locales/ja.js +19 -0
- package/lib/locales/ko.js +18 -0
- package/lib/locales/pt.js +20 -0
- package/lib/locales/ru.js +21 -0
- package/lib/locales/th.js +18 -0
- package/lib/locales/vi.js +18 -0
- package/lib/locales/zh-tw.js +17 -0
- package/lib/locales/zh.js +17 -0
- package/lib/migrations/1.0.21-update-config.js +34 -0
- package/lib/migrations/1.0.22-max-memory.js +40 -0
- package/lib/migrations/1.0.25.js +36 -0
- package/lib/migrations/1.0.32-update-config.js +30 -0
- package/lib/migrations/1.0.33-blocklets.js +33 -0
- package/lib/migrations/1.0.36-snapshot.js +10 -0
- package/lib/migrations/1.1.10-team.js +26 -0
- package/lib/migrations/1.1.9-snapshot.js +7 -0
- package/lib/migrations/1.16.11-component-status.js +22 -0
- package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
- package/lib/migrations/1.16.6-chain-info.js +78 -0
- package/lib/migrations/1.16.8-component-title.js +66 -0
- package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
- package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
- package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
- package/lib/migrations/1.4.5-access-key.js +18 -0
- package/lib/migrations/1.5.0-site.js +34 -0
- package/lib/migrations/1.5.15-site.js +184 -0
- package/lib/migrations/1.5.20-registry.js +15 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
- package/lib/migrations/1.6.4-security.js +59 -0
- package/lib/migrations/1.6.5-security.js +60 -0
- package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
- package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
- package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
- package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
- package/lib/migrations/1.7.20-blocklet-component.js +41 -0
- package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
- package/lib/migrations/README.md +71 -0
- package/lib/migrations/index.js +215 -0
- package/lib/monitor/blocklet-runtime-monitor.js +204 -0
- package/lib/monitor/get-history-list.js +37 -0
- package/lib/monitor/node-monit-sender.js +99 -0
- package/lib/monitor/node-runtime-monitor.js +205 -0
- package/lib/processes/updater.js +186 -0
- package/lib/router/helper.js +1653 -0
- package/lib/router/index.js +341 -0
- package/lib/router/manager.js +806 -0
- package/lib/states/README.md +38 -0
- package/lib/states/access-key.js +124 -0
- package/lib/states/access-policy.js +29 -0
- package/lib/states/audit-log.js +734 -0
- package/lib/states/backup.js +165 -0
- package/lib/states/base.js +25 -0
- package/lib/states/blocklet-extras.js +257 -0
- package/lib/states/blocklet.js +755 -0
- package/lib/states/cache.js +23 -0
- package/lib/states/connect-account.js +8 -0
- package/lib/states/index.js +76 -0
- package/lib/states/job.js +8 -0
- package/lib/states/migration.js +34 -0
- package/lib/states/node.js +324 -0
- package/lib/states/notification.js +81 -0
- package/lib/states/passport.js +8 -0
- package/lib/states/project.js +119 -0
- package/lib/states/release.js +50 -0
- package/lib/states/response-header-policy.js +30 -0
- package/lib/states/routing-snapshot.js +146 -0
- package/lib/states/runtime-insight.js +25 -0
- package/lib/states/security-rule.js +30 -0
- package/lib/states/session.js +53 -0
- package/lib/states/site.js +102 -0
- package/lib/states/tag.js +8 -0
- package/lib/states/traffic-insight.js +25 -0
- package/lib/states/user-session.js +8 -0
- package/lib/states/user.js +717 -0
- package/lib/states/verify-code.js +152 -0
- package/lib/states/webhook.js +66 -0
- package/lib/team/manager.js +508 -0
- package/lib/util/blocklet.js +2182 -0
- package/lib/util/cache.js +63 -0
- package/lib/util/chain.js +29 -0
- package/lib/util/default-node-config.js +46 -0
- package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
- package/lib/util/docker/check-docker-has-image.js +23 -0
- package/lib/util/docker/check-docker-installed.js +32 -0
- package/lib/util/docker/check-docker-run-history.js +18 -0
- package/lib/util/docker/check-need-run-docker.js +32 -0
- package/lib/util/docker/create-docker-image.js +65 -0
- package/lib/util/docker/debian-dockerfile.js +50 -0
- package/lib/util/docker/docker-container-prune.js +75 -0
- package/lib/util/docker/docker-exec-chown.js +39 -0
- package/lib/util/docker/docker-exec.js +68 -0
- package/lib/util/docker/docker-remove-by-name.js +20 -0
- package/lib/util/docker/get-docker-runtime-info.js +39 -0
- package/lib/util/docker/parse-docker-name.js +10 -0
- package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
- package/lib/util/docker/shard-network.js +10 -0
- package/lib/util/domain-status.js +118 -0
- package/lib/util/get-accessible-external-node-ip.js +92 -0
- package/lib/util/get-dynamic-components.js +47 -0
- package/lib/util/get-meta-from-url.js +30 -0
- package/lib/util/get-migration-scripts.js +36 -0
- package/lib/util/get-safe-env.js +12 -0
- package/lib/util/index.js +522 -0
- package/lib/util/install-external-dependencies.js +67 -0
- package/lib/util/ip.js +53 -0
- package/lib/util/launcher.js +475 -0
- package/lib/util/log.js +431 -0
- package/lib/util/maintain.js +178 -0
- package/lib/util/promise-debounce.js +29 -0
- package/lib/util/promise-once.js +14 -0
- package/lib/util/promise-spawn.js +93 -0
- package/lib/util/queue.js +44 -0
- package/lib/util/ready.js +89 -0
- package/lib/util/request.js +10 -0
- package/lib/util/requirement.js +61 -0
- package/lib/util/reset-node.js +166 -0
- package/lib/util/rotator.js +194 -0
- package/lib/util/router.js +122 -0
- package/lib/util/rpc.js +78 -0
- package/lib/util/spaces.js +102 -0
- package/lib/util/store.js +184 -0
- package/lib/util/sysinfo.js +46 -0
- package/lib/util/ua.js +54 -0
- package/lib/validators/backup.js +34 -0
- package/lib/validators/blocklet-extra.js +18 -0
- package/lib/validators/node.js +73 -0
- package/lib/validators/permission.js +38 -0
- package/lib/validators/project.js +39 -0
- package/lib/validators/role.js +64 -0
- package/lib/validators/router.js +192 -0
- package/lib/validators/space-gateway.js +33 -0
- package/lib/validators/trusted-factory.js +28 -0
- package/lib/validators/trusted-passport.js +32 -0
- package/lib/validators/user.js +62 -0
- package/lib/validators/util.js +92 -0
- package/lib/validators/webhook.js +42 -0
- package/lib/webhook/index.js +216 -0
- package/lib/webhook/reduce-queue.js +12 -0
- package/lib/webhook/sender/api/index.js +67 -0
- package/lib/webhook/sender/base.js +11 -0
- package/lib/webhook/sender/index.js +44 -0
- package/lib/webhook/sender/slack/index.js +167 -0
- package/lib/webhook/sender/wallet/index.js +62 -0
- package/package.json +107 -34
- package/examples/BatchClient.js +0 -61
- package/examples/compressor/example.js +0 -7
- package/examples/jsonrpcserver/rpcmethod.js +0 -21
- package/examples/jsonrpcserver/rpcrequest.js +0 -20
- package/examples/jsonrpcserver/rpctest.js +0 -6
- package/examples/loader-pipes/test-mc.js +0 -52
- package/examples/loader-pipes/test.js +0 -51
- package/examples/mc-test.js +0 -44
- package/examples/redisdebug.js +0 -80
- package/lib/cache/CFMemcache.js +0 -57
- package/lib/cache/CacheLoader.js +0 -217
- package/lib/cache/Memcache.js +0 -406
- package/lib/class/Class.js +0 -54
- package/lib/client/MemcacheAdapter.js +0 -139
- package/lib/client/Memcached.js +0 -142
- package/lib/client/MemcachedSocket.js +0 -570
- package/lib/client/MySQLPool.js +0 -153
- package/lib/client/PGPool.js +0 -296
- package/lib/client/Redis.js +0 -787
- package/lib/client/S3.js +0 -103
- package/lib/client/S3Client.js +0 -392
- package/lib/client/pg/CursorQueryWorker.js +0 -160
- package/lib/client/rabbitmq/RbmqChannel.js +0 -61
- package/lib/client/rabbitmq/RbmqConfig.js +0 -144
- package/lib/client/rabbitmq/RbmqConnection.js +0 -259
- package/lib/client/rabbitmq/RbmqExchange.js +0 -112
- package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
- package/lib/client/rabbitmq/RbmqMessage.js +0 -120
- package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
- package/lib/client/rabbitmq/RbmqQueue.js +0 -87
- package/lib/client/rabbitmq/index.js +0 -8
- package/lib/common/Assertions.js +0 -184
- package/lib/common/Merge.js +0 -32
- package/lib/common/Net.js +0 -56
- package/lib/common/Process.js +0 -20
- package/lib/common/Random.js +0 -53
- package/lib/common/Sort.js +0 -19
- package/lib/common/Types.js +0 -163
- package/lib/credentials/CredentialsProvider.js +0 -45
- package/lib/credentials/Manager.js +0 -101
- package/lib/crypto/Crypto.js +0 -66
- package/lib/data/BinaryData.js +0 -363
- package/lib/data/Compressor.js +0 -83
- package/lib/data/FormData.js +0 -144
- package/lib/data/Mime.js +0 -45
- package/lib/event/ErrorEvent.js +0 -71
- package/lib/event/Event.js +0 -20
- package/lib/event/EventDispatcher.js +0 -157
- package/lib/http/ConnectionPool.js +0 -82
- package/lib/http/ExpressServer.js +0 -19
- package/lib/http/Headers.js +0 -165
- package/lib/http/Loader.js +0 -584
- package/lib/http/Message.js +0 -189
- package/lib/http/Request.js +0 -848
- package/lib/http/RequestProcessor.js +0 -150
- package/lib/http/Response.js +0 -850
- package/lib/http/Server.js +0 -267
- package/lib/http/Socket.js +0 -157
- package/lib/http/Url.js +0 -2
- package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
- package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
- package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
- package/lib/jsonrpc/JsonRpcError.js +0 -191
- package/lib/jsonrpc/JsonRpcMethod.js +0 -67
- package/lib/jsonrpc/JsonRpcRequest.js +0 -224
- package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
- package/lib/jsonrpc/JsonRpcResponse.js +0 -175
- package/lib/jsonrpc/JsonRpcServer.js +0 -81
- package/lib/logger/EmptyLogger.js +0 -15
- package/lib/logger/LoggerFactory.js +0 -20
- package/lib/logger/WildFireLogger.js +0 -267
- package/lib/pattern/Pool.js +0 -187
- package/lib/pattern/decorator/AbstractDecorator.js +0 -49
- package/lib/pattern/decorator/DecoratorChain.js +0 -285
- package/lib/util/DeviceDetector.js +0 -153
- package/lib/yaml/YAML.js +0 -46
- package/patterns.conf +0 -6
- package/tests/cache/CacheLoaderSpec.js +0 -7
- package/tests/class/ClassSpec.js +0 -106
- package/tests/client/MemcachedSocketSpec.js +0 -1228
- package/tests/client/MemcachedSpec.js +0 -77
- package/tests/client/MySQLPoolSpec.js +0 -231
- package/tests/client/PGPoolSpec.js +0 -479
- package/tests/client/RedisSpec.js +0 -471
- package/tests/client/S3ClientSpec.js +0 -26
- package/tests/client/S3Spec.js +0 -129
- package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
- package/tests/common/AssertionsSpec.js +0 -278
- package/tests/common/NetSpec.js +0 -6
- package/tests/common/RandomSpec.js +0 -35
- package/tests/common/TypesSpec.js +0 -7
- package/tests/credentials/CredentialsProviderSpec.js +0 -46
- package/tests/crypto/CryptoSpec.js +0 -33
- package/tests/data/BinaryDataSpec.js +0 -50
- package/tests/data/CompressorSpec.js +0 -7
- package/tests/data/FormDataSpec.js +0 -7
- package/tests/data/MimeSpec.js +0 -7
- package/tests/event/ErrorEventSpec.js +0 -20
- package/tests/event/EventDispatcherSpec.js +0 -319
- package/tests/event/EventSpec.js +0 -17
- package/tests/http/ConnectionPoolSpec.js +0 -7
- package/tests/http/HeadersSpec.js +0 -79
- package/tests/http/LoaderSpec.js +0 -43
- package/tests/http/MessageSpec.js +0 -251
- package/tests/http/RequestProcessorSpec.js +0 -124
- package/tests/http/RequestSpec.js +0 -651
- package/tests/http/ResponseSpec.js +0 -491
- package/tests/http/ServerSpec.js +0 -7
- package/tests/http/SocketSpec.js +0 -7
- package/tests/http/UrlSpec.js +0 -14
- package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
- package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
- package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
- package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
- package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
- package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
- package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
- package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
- package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
- package/tests/pattern/PoolSpec.js +0 -180
- package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
- package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
- package/tests/yaml/YAMLSpec.js +0 -132
package/lib/http/Loader.js
DELETED
|
@@ -1,584 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @overview Loader
|
|
3
|
-
* @copyright Dreamlab Onet.pl sp. z. o o 2012
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var http = require('http'),
|
|
7
|
-
https = require('https'),
|
|
8
|
-
util = require('util');
|
|
9
|
-
|
|
10
|
-
var Request = require('./Request.js').Request,
|
|
11
|
-
Response = require('./Response.js').Response,
|
|
12
|
-
Event = require('../event/Event.js').Event,
|
|
13
|
-
ErrorEvent = require('../event/ErrorEvent.js').ErrorEvent,
|
|
14
|
-
EventDispatcher = require('../event/EventDispatcher.js').EventDispatcher,
|
|
15
|
-
Types = require('../common/Types.js');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Http Loader
|
|
19
|
-
* @class Loader
|
|
20
|
-
* @classdesc Processes given requests and returns the result
|
|
21
|
-
* @extends EventDispatcher
|
|
22
|
-
* @param {Request} request request to process
|
|
23
|
-
*/
|
|
24
|
-
var Loader = function (request) {
|
|
25
|
-
EventDispatcher.call(this);
|
|
26
|
-
this._buffer = null;
|
|
27
|
-
this._request = null;
|
|
28
|
-
this._timeout = 8000;
|
|
29
|
-
this._timer = null;
|
|
30
|
-
this._followRedirects = true;
|
|
31
|
-
this._maxRedirectsCount = 10;
|
|
32
|
-
this._currentRedirectsCount = 0;
|
|
33
|
-
this._dataBuffering = true;
|
|
34
|
-
this._agent = false;
|
|
35
|
-
this._errorEmited = false;
|
|
36
|
-
this._requestStart = null;
|
|
37
|
-
this._requestLength = null;
|
|
38
|
-
this._logStatus = true;
|
|
39
|
-
|
|
40
|
-
this.setRequest(request);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
Loader.prototype = Object.create(EventDispatcher.prototype);
|
|
44
|
-
|
|
45
|
-
Loader.prototype.setLogStatus = function (value) {
|
|
46
|
-
this._logStatus = !!value;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* enables/disables data buffering
|
|
52
|
-
* @method
|
|
53
|
-
* @param {Boolean} buffering
|
|
54
|
-
* @returns {Loader}
|
|
55
|
-
*/
|
|
56
|
-
Loader.prototype.setDataBuffering = function (buffering) {
|
|
57
|
-
this._dataBuffering = buffering;
|
|
58
|
-
return this;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* callback responsible for gathering response chunks
|
|
63
|
-
* @method
|
|
64
|
-
* @private
|
|
65
|
-
* @param {Server.HttpResponse} serverResponse
|
|
66
|
-
* @fires Loader.Event.HEADERS
|
|
67
|
-
* @fires Loader.Event.PROGRESS
|
|
68
|
-
*/
|
|
69
|
-
Loader.prototype._handleServerResponse = function (serverResponse) {
|
|
70
|
-
var dataLength = 0,
|
|
71
|
-
buffers = [],
|
|
72
|
-
self = this,
|
|
73
|
-
response = new Response();
|
|
74
|
-
|
|
75
|
-
response.setStatusCode(serverResponse.statusCode);
|
|
76
|
-
response.setHeaders(serverResponse.headers);
|
|
77
|
-
response.setHttpVersion(serverResponse.httpVersion);
|
|
78
|
-
|
|
79
|
-
//console.log(">>>>> LOADER headers");
|
|
80
|
-
this.dispatchEvent(new Event(Loader.Event.HEADERS, {
|
|
81
|
-
"statusCode": serverResponse.statusCode,
|
|
82
|
-
"headers": serverResponse.headers,
|
|
83
|
-
"httpVersion": serverResponse.httpVersion,
|
|
84
|
-
"body": null,
|
|
85
|
-
"response": response,
|
|
86
|
-
"stream": serverResponse
|
|
87
|
-
}));
|
|
88
|
-
|
|
89
|
-
serverResponse.addListener('data', function (buffer) {
|
|
90
|
-
//console.log(">>>>> LOADER data");
|
|
91
|
-
if (self._dataBuffering) {
|
|
92
|
-
buffers.push(buffer);
|
|
93
|
-
dataLength += buffer.length;
|
|
94
|
-
}
|
|
95
|
-
response.write(buffer);
|
|
96
|
-
self.dispatchEvent(new Event(Loader.Event.PROGRESS, buffer));
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
serverResponse.addListener('end', function () {
|
|
100
|
-
//console.log(">>>>> LOADER end");
|
|
101
|
-
self._buffer = new Buffer(dataLength);
|
|
102
|
-
var bufferPosition = 0;
|
|
103
|
-
for (var i = 0, l = buffers.length; i < l; i++) {
|
|
104
|
-
buffers[i].copy(self._buffer, bufferPosition);
|
|
105
|
-
bufferPosition += buffers[i].length;
|
|
106
|
-
}
|
|
107
|
-
response.end();
|
|
108
|
-
self._onEnd(serverResponse);
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* sets timer which is responsible for timeout detection
|
|
114
|
-
* @method
|
|
115
|
-
* @private
|
|
116
|
-
* @param {Server.HttpRequest} request
|
|
117
|
-
* @fires Loader.Event.ERROR
|
|
118
|
-
*/
|
|
119
|
-
Loader.prototype._setTimer = function (request) {
|
|
120
|
-
var self = this;
|
|
121
|
-
this._timer = setTimeout(function () {
|
|
122
|
-
request.removeAllListeners('response');
|
|
123
|
-
request.abort();
|
|
124
|
-
self._log();
|
|
125
|
-
if (!self._errorEmited) {
|
|
126
|
-
self.dispatchEvent(new ErrorEvent(Loader.Event.ERROR, null, -3, 'Http response timeout'));
|
|
127
|
-
self._errorEmited = true;
|
|
128
|
-
}
|
|
129
|
-
}, this.getTimeout());
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* clears timer handle which is responsible for timeout detection
|
|
134
|
-
* @method
|
|
135
|
-
* @private
|
|
136
|
-
*/
|
|
137
|
-
Loader.prototype._clearTimer = function () {
|
|
138
|
-
clearTimeout(this._timer);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* clears internal chunks array
|
|
143
|
-
* @method
|
|
144
|
-
* @private
|
|
145
|
-
*/
|
|
146
|
-
Loader.prototype._clearChunks = function () {
|
|
147
|
-
this._buffer = [];
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* check for 3xx following
|
|
152
|
-
* @method
|
|
153
|
-
* @private
|
|
154
|
-
* @param {Server.HttpResponse} response
|
|
155
|
-
* @fires Loader.Event.ERROR
|
|
156
|
-
* @returns {Boolean}
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
Loader.prototype._checkForRedirect = function (response) {
|
|
160
|
-
var requestMethod = this._request.getMethod();
|
|
161
|
-
if (response.statusCode >= 300 && response.statusCode < 400 &&
|
|
162
|
-
response.headers.hasOwnProperty('location') && this._followRedirects &&
|
|
163
|
-
requestMethod != Request.PUT && requestMethod != Request.POST) {
|
|
164
|
-
|
|
165
|
-
response.removeAllListeners('data');
|
|
166
|
-
response.removeAllListeners('end');
|
|
167
|
-
|
|
168
|
-
if (this._currentRedirectsCount >= this._maxRedirectsCount) {
|
|
169
|
-
if (!this._errorEmited) {
|
|
170
|
-
this.dispatchEvent(new ErrorEvent(Loader.Event.ERROR, null, -4, 'maxRedirectsCount reached, stopping'));
|
|
171
|
-
this._errorEmited = true;
|
|
172
|
-
}
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
this._currentRedirectsCount++;
|
|
177
|
-
|
|
178
|
-
var host = this._request.getHost();
|
|
179
|
-
var connectionHost = this._request.getConnectionHost();
|
|
180
|
-
|
|
181
|
-
this._request.setUrl(response.headers.location);
|
|
182
|
-
/* redirect with no host */
|
|
183
|
-
if (!this._request.getHost() && host) {
|
|
184
|
-
this._request.setHost(host);
|
|
185
|
-
}
|
|
186
|
-
if (!this._request.getConnectionHost() && connectionHost) {
|
|
187
|
-
this._request.setConnectionHost(connectionHost);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
this._clearChunks();
|
|
191
|
-
this.load();
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
return false;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
Loader.prototype._log = function (res, type) {
|
|
198
|
-
|
|
199
|
-
var req = this.getRequest();
|
|
200
|
-
var code = 0;
|
|
201
|
-
var len = 0;
|
|
202
|
-
|
|
203
|
-
if (res) {
|
|
204
|
-
code = res.statusCode;
|
|
205
|
-
len = this._buffer.length;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
var upstream = req.getHeader('host') || '-';
|
|
209
|
-
var gateway = req.getConnectionHost() || '-';
|
|
210
|
-
var tt = Date.now() - this._requestStart;
|
|
211
|
-
var rel = this._requestLength || 0;
|
|
212
|
-
|
|
213
|
-
type = type || 'http';
|
|
214
|
-
|
|
215
|
-
if (this._logStatus) {
|
|
216
|
-
console.info('Loader/Monitoring: upstream=%s code=%s tt=%s len=%s method=%s gateway=%s type=%s reqlen=%s', upstream, code, tt, len, req.getMethod(), gateway, type, rel);
|
|
217
|
-
} else {
|
|
218
|
-
console.log('Loader/Monitoring: upstream=%s code=%s tt=%s len=%s method=%s gateway=%s type=%s reqlen=%s', upstream, code, tt, len, req.getMethod(), gateway, type, rel);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* called on request end, when whole data has been retreived from server
|
|
225
|
-
* @method
|
|
226
|
-
* @private
|
|
227
|
-
* @param {http.IncomingMessage} response
|
|
228
|
-
* @fires Loader.Event.ERROR
|
|
229
|
-
* @fires Loader.Event.LOADED
|
|
230
|
-
*/
|
|
231
|
-
Loader.prototype._onEnd = function (response) {
|
|
232
|
-
var requestMethod = this._request.getMethod();
|
|
233
|
-
|
|
234
|
-
this._log(response);
|
|
235
|
-
|
|
236
|
-
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.hasOwnProperty('location') && this._followRedirects && requestMethod != Request.PUT && requestMethod != Request.POST) {
|
|
237
|
-
if (this._currentRedirectsCount >= this._maxRedirectsCount) {
|
|
238
|
-
if (!this._errorEmited) {
|
|
239
|
-
this.dispatchEvent(new ErrorEvent(Loader.Event.ERROR, null, -4, 'maxRedirectsCount reached, stopping'));
|
|
240
|
-
this._errorEmited = true;
|
|
241
|
-
}
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
this._currentRedirectsCount++;
|
|
246
|
-
this._request.setUrl(response.headers.location);
|
|
247
|
-
this._clearChunks();
|
|
248
|
-
this.load();
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
var data = this._parseResponse(response);
|
|
253
|
-
|
|
254
|
-
if (data == false) {
|
|
255
|
-
//tutaj zakladamy ze _parseResponse obsluzyl blad
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
this.dispatchEvent(new Event(Loader.Event.LOADED, data));
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* creates Response from node http.IncomingMessage and received data chunks
|
|
264
|
-
* @method
|
|
265
|
-
* @private
|
|
266
|
-
* @param {http.IncomingMessage} response
|
|
267
|
-
*/
|
|
268
|
-
Loader.prototype._parseResponse = function (response) {
|
|
269
|
-
return new Response({
|
|
270
|
-
"statusCode": response.statusCode,
|
|
271
|
-
"headers": response.headers,
|
|
272
|
-
"httpVersion": response.httpVersion,
|
|
273
|
-
"body": this._buffer
|
|
274
|
-
});
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* creates node http.request compatible object based on given request
|
|
279
|
-
* @method
|
|
280
|
-
* @private
|
|
281
|
-
* @param {Request} request
|
|
282
|
-
* @throws Loader.Exception.INCOMPLETE_REQUEST
|
|
283
|
-
*/
|
|
284
|
-
Loader.prototype._createRequest = function (request) {
|
|
285
|
-
var ua = request.getHeader('user-agent');
|
|
286
|
-
if (!ua) {
|
|
287
|
-
request.setHeader('user-agent', 'nodejs ' + process.env.OPAL_IDENTITY || '', true);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
var host = request.getConnectionHost() || request.getHost();
|
|
291
|
-
//FIXME to pasuje rozwiazac w klasie Request gdy klonuje inny request
|
|
292
|
-
host = host.replace(':'+request.getPort(), '');
|
|
293
|
-
|
|
294
|
-
var port = request.getPort();
|
|
295
|
-
var path = request.getPath();
|
|
296
|
-
var method = request.getMethod();
|
|
297
|
-
var headers = request.getHeaders();
|
|
298
|
-
|
|
299
|
-
if (!host || !port || !path || !method || !headers) {
|
|
300
|
-
this._log();
|
|
301
|
-
throw Loader.Exception.INCOMPLETE_REQUEST;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
var retValue = {
|
|
305
|
-
host: host,
|
|
306
|
-
port: +port,
|
|
307
|
-
path: path + request.getQueryString(),
|
|
308
|
-
method: method,
|
|
309
|
-
headers: headers
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
if (!this._agent) {
|
|
313
|
-
retValue.agent = false;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return retValue;
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* sets timeout in miliseconds
|
|
321
|
-
* @method
|
|
322
|
-
* @param {Number} ms
|
|
323
|
-
* @returns {Loader}
|
|
324
|
-
*/
|
|
325
|
-
Loader.prototype.setTimeout = function (ms) {
|
|
326
|
-
this._timeout = ms;
|
|
327
|
-
return this;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* gets timeout in miliseconds
|
|
332
|
-
* @method
|
|
333
|
-
* @returns {Number}
|
|
334
|
-
*/
|
|
335
|
-
Loader.prototype.getTimeout = function () {
|
|
336
|
-
return this._timeout;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
/** sets followRedirects
|
|
340
|
-
* @method
|
|
341
|
-
* @param {Boolean} follow
|
|
342
|
-
* @throws Loader.Exception.FOLLOW_REDIRECTS_TYPE_ERROR
|
|
343
|
-
* @returns {Loader}
|
|
344
|
-
*/
|
|
345
|
-
Loader.prototype.setFollowRedirects = function (follow) {
|
|
346
|
-
if (typeof follow == 'boolean') {
|
|
347
|
-
this._followRedirects = follow;
|
|
348
|
-
} else {
|
|
349
|
-
throw Loader.Exception.FOLLOW_REDIRECTS_TYPE_ERROR;
|
|
350
|
-
}
|
|
351
|
-
return this;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* gets followRedirects
|
|
356
|
-
* @method
|
|
357
|
-
* @returns {Boolean}
|
|
358
|
-
*/
|
|
359
|
-
Loader.prototype.getFollowRedirects = function () {
|
|
360
|
-
return this._followRedirects;
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* sets maxRedirects after which processing request will be aborted
|
|
365
|
-
* @method
|
|
366
|
-
* @param {Number} count
|
|
367
|
-
* @returns {Loader}
|
|
368
|
-
*/
|
|
369
|
-
Loader.prototype.setMaxRedirectsCount = function (count) {
|
|
370
|
-
this._maxRedirectsCount = count;
|
|
371
|
-
return this;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* gets maxRedirects count
|
|
376
|
-
* @method
|
|
377
|
-
* @returns {Number}
|
|
378
|
-
*/
|
|
379
|
-
Loader.prototype.getMaxRedirectsCount = function () {
|
|
380
|
-
return this._maxRedirectsCount;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* sets request object to process,
|
|
385
|
-
* request to process is a copy from a original request
|
|
386
|
-
* @method
|
|
387
|
-
* @param {Request} request
|
|
388
|
-
* @throws Loader.Exception.WRONG_REQUEST_INSTANCE
|
|
389
|
-
*/
|
|
390
|
-
Loader.prototype.setRequest = function (request) {
|
|
391
|
-
if (request && !(request instanceof Request)) {
|
|
392
|
-
throw Loader.Exception.WRONG_REQUEST_INSTANCE;
|
|
393
|
-
} else if (request) {
|
|
394
|
-
this._request = new Request(request);
|
|
395
|
-
this._currentRedirectCount = 0;
|
|
396
|
-
this._clearChunks();
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* returns request (a copy of it) which is going to be processed
|
|
402
|
-
*/
|
|
403
|
-
Loader.prototype.getRequest = function () {
|
|
404
|
-
return this._request;
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* aborts a request, clears timer, dispatches ABORTED event
|
|
409
|
-
* @method
|
|
410
|
-
* @fires Loader.Event.ABORTED
|
|
411
|
-
*/
|
|
412
|
-
Loader.prototype.abort = function () {
|
|
413
|
-
if (this._clientRequest) {
|
|
414
|
-
this._clientRequest.abort();
|
|
415
|
-
}
|
|
416
|
-
this._clearTimer();
|
|
417
|
-
this.dispatchEvent(new Event(Loader.Event.ABORTED, 'Aborted'));
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* set agent value
|
|
422
|
-
* @param {Boolean} value
|
|
423
|
-
*/
|
|
424
|
-
Loader.prototype.setAgent = function (value) {
|
|
425
|
-
if (!Types.isBoolean(value))
|
|
426
|
-
throw new Error(Loader.Exception.AGENT_VALUE);
|
|
427
|
-
|
|
428
|
-
this._agent = value;
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* makes request to the backend system based on the request object
|
|
433
|
-
* @method
|
|
434
|
-
* @param {Request} request
|
|
435
|
-
* @fires Loader.Event.ERROR
|
|
436
|
-
* @throws Loader.Exception.REQUEST_NOT_SET
|
|
437
|
-
*/
|
|
438
|
-
Loader.prototype.load = function (request) {
|
|
439
|
-
this.setRequest(request);
|
|
440
|
-
this._errorEmited = false;
|
|
441
|
-
|
|
442
|
-
if (this._request == null) {
|
|
443
|
-
throw Loader.Exception.REQUEST_NOT_SET;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
var that = this;
|
|
447
|
-
|
|
448
|
-
this._requestStart = Date.now();
|
|
449
|
-
|
|
450
|
-
var options = this._createRequest(this._request);
|
|
451
|
-
|
|
452
|
-
var httpClient = http;
|
|
453
|
-
if(this._request.getProto() == 'https:') {
|
|
454
|
-
httpClient = https;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
this._clientRequest = httpClient.request(options, function (serverResponse) {
|
|
458
|
-
that._clearTimer();
|
|
459
|
-
if (that._checkForRedirect(serverResponse)) {
|
|
460
|
-
return;
|
|
461
|
-
} else {
|
|
462
|
-
that._handleServerResponse(serverResponse);
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
this._clientRequest.addListener('error', function (e) {
|
|
467
|
-
options.agent = null;
|
|
468
|
-
console.error('LOADER ERROR NODE REQUEST: ' + util.inspect(e, true, 20) + ' Options: ' + util.inspect(options, true, 20));
|
|
469
|
-
that._clearTimer();
|
|
470
|
-
that._log();
|
|
471
|
-
if (!that._errorEmited) {
|
|
472
|
-
that.dispatchEvent(new ErrorEvent(Loader.Event.ERROR, e, -1, 'Http request error: ' + e.message));
|
|
473
|
-
that._errorEmited = true;
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
// jezeli sa dane np POST to tez je wpisuje
|
|
478
|
-
if (this._request.getBody().length() > 0) {
|
|
479
|
-
var buf = this._request.getBody().toBuffer();
|
|
480
|
-
|
|
481
|
-
this._requestLength = buf.length;
|
|
482
|
-
this._clientRequest.write(buf);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
this._clientRequest.end();
|
|
486
|
-
|
|
487
|
-
this._setTimer(this._clientRequest);
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* @static
|
|
492
|
-
* @namespace
|
|
493
|
-
* @constant
|
|
494
|
-
*/
|
|
495
|
-
Loader.Event = {};
|
|
496
|
-
|
|
497
|
-
/**
|
|
498
|
-
* @static
|
|
499
|
-
* @constant
|
|
500
|
-
* @type {String}
|
|
501
|
-
* @default
|
|
502
|
-
*/
|
|
503
|
-
Loader.Event.HEADERS = "Loader_HEADERS";
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* @static
|
|
507
|
-
* @constant
|
|
508
|
-
* @type {String}
|
|
509
|
-
* @default
|
|
510
|
-
*/
|
|
511
|
-
Loader.Event.PROGRESS = "Loader_PROGRESS";
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* @static
|
|
515
|
-
* @constant
|
|
516
|
-
* @type {String}
|
|
517
|
-
* @default
|
|
518
|
-
*/
|
|
519
|
-
Loader.Event.LOADED = "Loader_LOADED";
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
* @static
|
|
523
|
-
* @constant
|
|
524
|
-
* @type {String}
|
|
525
|
-
* @default
|
|
526
|
-
*/
|
|
527
|
-
Loader.Event.ABORTED = "Loader_ABORTED";
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* @static
|
|
531
|
-
* @constant
|
|
532
|
-
* @type {String}
|
|
533
|
-
* @default
|
|
534
|
-
*/
|
|
535
|
-
Loader.Event.ERROR = "Loader_ERROR";
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* @static
|
|
539
|
-
* @namespace
|
|
540
|
-
* @constant
|
|
541
|
-
*/
|
|
542
|
-
Loader.Exception = {};
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* @static
|
|
546
|
-
* @constant
|
|
547
|
-
* @type {String}
|
|
548
|
-
* @default
|
|
549
|
-
*/
|
|
550
|
-
Loader.Exception.INCOMPLETE_REQUEST = 'Given request misses some key values';
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* @static
|
|
554
|
-
* @constant
|
|
555
|
-
* @type {String}
|
|
556
|
-
* @default
|
|
557
|
-
*/
|
|
558
|
-
Loader.Exception.REQUEST_NOT_SET = 'Request has not been set';
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* @static
|
|
562
|
-
* @constant
|
|
563
|
-
* @type {String}
|
|
564
|
-
* @default
|
|
565
|
-
*/
|
|
566
|
-
Loader.Exception.WRONG_REQUEST_INSTANCE = 'Given request is not a instance of Request';
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* @static
|
|
570
|
-
* @constant
|
|
571
|
-
* @type {String}
|
|
572
|
-
* @default
|
|
573
|
-
*/
|
|
574
|
-
Loader.Exception.FOLLOW_REDIRECTS_TYPE_ERROR = 'setFollowRedirects requires an argument to be a boolean';
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* @static
|
|
578
|
-
* @constant
|
|
579
|
-
* @type {String}
|
|
580
|
-
* @default
|
|
581
|
-
*/
|
|
582
|
-
Loader.Exception.AGENT_VALUE = 'Agent param value must be a type of Boolean';
|
|
583
|
-
|
|
584
|
-
exports.Loader = Loader;
|