@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/Request.js
DELETED
|
@@ -1,848 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @overview Request
|
|
3
|
-
* @copyright Dreamlab Onet.pl sp. z. o o 2012
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var http = require('http');
|
|
7
|
-
var urlParser = require('@ohos-ports/uriparser');
|
|
8
|
-
|
|
9
|
-
var Types = require('../common/Types.js').Types;
|
|
10
|
-
var Message = require('./Message.js').Message;
|
|
11
|
-
var BinaryData = require('../data/BinaryData.js').BinaryData;
|
|
12
|
-
var FormData = require('../data/FormData.js').FormData;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Http Request
|
|
17
|
-
* @class Request
|
|
18
|
-
* @classdesc Object that represents http request
|
|
19
|
-
* @extends Message
|
|
20
|
-
* @throw Request.Exception.REQUEST_CANNOT_BE_A_BUFFER
|
|
21
|
-
* @param {Object|String|Request|Buffer|http.IncomingMessage} params
|
|
22
|
-
* @return {Request}
|
|
23
|
-
*/
|
|
24
|
-
var Request = function (params) {
|
|
25
|
-
Message.call(this, params);
|
|
26
|
-
|
|
27
|
-
this._url = null;
|
|
28
|
-
this._search = null;
|
|
29
|
-
this._method = 'GET';
|
|
30
|
-
this._host = null;
|
|
31
|
-
this._port = null;
|
|
32
|
-
this._defaultPortChanged = false;
|
|
33
|
-
this._path = '/';
|
|
34
|
-
this._proto = 'http:';
|
|
35
|
-
this._authUser = null;
|
|
36
|
-
this._authPassword = null;
|
|
37
|
-
this._querySuffixes = {};
|
|
38
|
-
this._querySeparator = '&';
|
|
39
|
-
this._query = {};
|
|
40
|
-
this._clientAddress = null;
|
|
41
|
-
this._clientPort = null;
|
|
42
|
-
this._timeStart = null;
|
|
43
|
-
|
|
44
|
-
if (Buffer.isBuffer(params)) {
|
|
45
|
-
throw Request.Exception.REQUEST_CANNOT_BE_A_BUFFER;
|
|
46
|
-
} else if (Types.isString(params)) {
|
|
47
|
-
this.setUrl(params);
|
|
48
|
-
} else if (Types.isInstanceOf(params, Request)) {
|
|
49
|
-
this.setUrl(params.getUrl());
|
|
50
|
-
this.setMethod(params.getMethod());
|
|
51
|
-
this.setHeaders(params.getHeaders());
|
|
52
|
-
this.setBody(params.getBody());
|
|
53
|
-
this.setHttpVersion(params.getHttpVersion());
|
|
54
|
-
//connection host
|
|
55
|
-
this.setConnectionHost(params.getConnectionHost());
|
|
56
|
-
} else if (Types.isInstanceOf(params, http.IncomingMessage)) {
|
|
57
|
-
// 1831 - 1886
|
|
58
|
-
// 1500 - 1618
|
|
59
|
-
this.setMethod(params.method);
|
|
60
|
-
// 1483 - 1572
|
|
61
|
-
this.setHeaders(params.headers);
|
|
62
|
-
// 1416 - 1552
|
|
63
|
-
var httpVer = params.httpVersion;
|
|
64
|
-
// 1381 - 1483
|
|
65
|
-
this.setHttpVersion(httpVer);
|
|
66
|
-
// 1381 - 1483
|
|
67
|
-
// 1362 - 1488 (bez return this) 1388 - 1492
|
|
68
|
-
this.setBody(params.data);
|
|
69
|
-
// 1340 - 1453
|
|
70
|
-
this.setUrl(params.url);
|
|
71
|
-
this._clientAddress = params.client.remoteAddress;
|
|
72
|
-
this._clientPort = params.client.remotePort;
|
|
73
|
-
this._timeStart = (params.__timeStart || Date.now());
|
|
74
|
-
} else {
|
|
75
|
-
this.init(params);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
Request.prototype = Object.create(Message.prototype);
|
|
80
|
-
|
|
81
|
-
Request.prototype._cookieRegExpCache = {};
|
|
82
|
-
Request.prototype._preCookieRegexp = '((?:^|;)\\s?)';
|
|
83
|
-
Request.prototype._postCookieRegExp = '=([^;]+)(;\\s?|$)';
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Checks if given string is already encoded
|
|
87
|
-
* @method
|
|
88
|
-
* @private
|
|
89
|
-
* @param {String} str
|
|
90
|
-
* @return {Boolean}
|
|
91
|
-
*/
|
|
92
|
-
Request.prototype._isEncoded = function (str) {
|
|
93
|
-
return (str.indexOf("%") != -1 || str.indexOf("+") != -1);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Set cookie
|
|
98
|
-
* @method
|
|
99
|
-
* @param {String} cookie
|
|
100
|
-
* @return {Request}
|
|
101
|
-
*/
|
|
102
|
-
Request.prototype.setCookie = function (cookie) {
|
|
103
|
-
var cookies = this.headers.getHeader("cookie");
|
|
104
|
-
|
|
105
|
-
if (!cookies) {
|
|
106
|
-
cookies = '';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (cookies.length) {
|
|
110
|
-
cookies += '; ' + cookie;
|
|
111
|
-
} else {
|
|
112
|
-
cookies = cookie;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.headers.setHeader("cookie", cookies, true);
|
|
116
|
-
|
|
117
|
-
return this;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Get cookie
|
|
122
|
-
* @method
|
|
123
|
-
* @param {String} cookieName
|
|
124
|
-
* @return {String|null}
|
|
125
|
-
*/
|
|
126
|
-
Request.prototype.getCookie = function (cookieName) {
|
|
127
|
-
var cookies = this.headers.getHeader('cookie');
|
|
128
|
-
|
|
129
|
-
if (!cookies) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
var result = cookies.match(this._getCookieRegexp(cookieName));
|
|
134
|
-
|
|
135
|
-
if (result && result[2]) {
|
|
136
|
-
return result[2];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return null;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Remove cookie
|
|
144
|
-
* @method
|
|
145
|
-
* @param {String} cookieName
|
|
146
|
-
* @return {null|Boolean}
|
|
147
|
-
*/
|
|
148
|
-
Request.prototype.removeCookie = function (cookieName) {
|
|
149
|
-
var cookies = this.headers.getHeader('cookie');
|
|
150
|
-
|
|
151
|
-
if (!cookies) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
cookies = cookies.replace(this._getCookieRegexp(cookieName), '$1').replace(/[; ]+$/, '');
|
|
156
|
-
|
|
157
|
-
this.headers.setHeader('cookie', cookies, true);
|
|
158
|
-
|
|
159
|
-
return true;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Returns cookie cached regexp
|
|
164
|
-
*
|
|
165
|
-
* @param {string} cookieName
|
|
166
|
-
* @return {RegExp} - regexp pattern for cookie
|
|
167
|
-
*/
|
|
168
|
-
Request.prototype._getCookieRegexp = function (cookieName) {
|
|
169
|
-
if (!this._cookieRegExpCache[cookieName]) {
|
|
170
|
-
this._cookieRegExpCache[cookieName] = new RegExp(this._preCookieRegexp + cookieName + this._postCookieRegExp);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return this._cookieRegExpCache[cookieName];
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Sets url of a service endpoint
|
|
179
|
-
* @method
|
|
180
|
-
* @param {String} url
|
|
181
|
-
* @returns {UrlRequest}
|
|
182
|
-
*/
|
|
183
|
-
Request.prototype.setUrl = function (url) {
|
|
184
|
-
this._url = url;
|
|
185
|
-
|
|
186
|
-
var matches = urlParser.parse(url);
|
|
187
|
-
|
|
188
|
-
if (matches.hasOwnProperty('auth')) {
|
|
189
|
-
this.setAuth(matches.auth);
|
|
190
|
-
} else {
|
|
191
|
-
this.setAuth('');
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (matches.hasOwnProperty('host')) {
|
|
195
|
-
this.setConnectionHost(matches.host);
|
|
196
|
-
} else {
|
|
197
|
-
this.setConnectionHost(this.getHost());
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (matches.hasOwnProperty('port')) {
|
|
201
|
-
this._defaultPortChanged = true;
|
|
202
|
-
this.setPort(parseInt(matches.port, 10));
|
|
203
|
-
} else {
|
|
204
|
-
this._defaultPortChanged = false;
|
|
205
|
-
this.setPort(80);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (matches.hasOwnProperty('protocol')) {
|
|
209
|
-
this.setProto(matches.protocol);
|
|
210
|
-
} else {
|
|
211
|
-
this.setProto('http:');
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (matches.hasOwnProperty('path')) {
|
|
215
|
-
var path = matches.path;
|
|
216
|
-
if (path[0] != '/') {
|
|
217
|
-
path = '/' + path;
|
|
218
|
-
}
|
|
219
|
-
this.setPath(path);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (matches.hasOwnProperty('query')) {
|
|
223
|
-
this.setQuery(matches.query);
|
|
224
|
-
if (matches.hasOwnProperty('queryArraySuffix')) {
|
|
225
|
-
this._querySuffixes = matches.queryArraySuffix;
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
this.setQuery({});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (matches.hasOwnProperty('querySeparator')) {
|
|
232
|
-
this._querySeparator = matches.querySeparator || '&';
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (matches.hasOwnProperty('search')) {
|
|
236
|
-
this._search = matches.search;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return this;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Returns url of a service endpoint
|
|
244
|
-
* @method
|
|
245
|
-
* @returns {String}
|
|
246
|
-
*/
|
|
247
|
-
Request.prototype.getUrl = function () {
|
|
248
|
-
if (this._url) {
|
|
249
|
-
return this._url;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
var url = '';
|
|
253
|
-
|
|
254
|
-
var proto = this.getProto();
|
|
255
|
-
if (proto) {
|
|
256
|
-
url += proto + '//';
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
var auth = this.getAuth();
|
|
260
|
-
if (auth) {
|
|
261
|
-
url += auth + '@';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
var host = this.getConnectionHost(),
|
|
265
|
-
port = this.getPort();
|
|
266
|
-
|
|
267
|
-
if (this.getHost()) {
|
|
268
|
-
host = this.getHost();
|
|
269
|
-
if (host.lastIndexOf(':') > 0) {
|
|
270
|
-
port = null;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
//jak mamy port i nie mamy pary http:80 i https:443 to doklejamy do hosta port
|
|
275
|
-
//dla http/https jesli port jest default to go nie zwracamy
|
|
276
|
-
if (port && !((proto === 'http:' && port == 80) || (proto === 'https:' && port == 443))) {
|
|
277
|
-
url += host + ':' + port;
|
|
278
|
-
} else {
|
|
279
|
-
url += host;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
var path = this.getPath();
|
|
283
|
-
if (path) {
|
|
284
|
-
url += path;
|
|
285
|
-
} else {
|
|
286
|
-
url += '/';
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
url += this.getQueryString();
|
|
290
|
-
|
|
291
|
-
this._url = url;
|
|
292
|
-
return url;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Returns query string component of an url
|
|
297
|
-
* @method
|
|
298
|
-
* @returns {String}
|
|
299
|
-
*/
|
|
300
|
-
Request.prototype.getQueryString = function () {
|
|
301
|
-
var url = '';
|
|
302
|
-
var query = this.getQuery();
|
|
303
|
-
if (this._search) {
|
|
304
|
-
return this._search;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (query) {
|
|
308
|
-
url += '?';
|
|
309
|
-
|
|
310
|
-
var tmp = '';
|
|
311
|
-
// to nie zadziala dla case test ącki
|
|
312
|
-
for (var key in query) {
|
|
313
|
-
if (query.hasOwnProperty(key)) {
|
|
314
|
-
if (Array.isArray(query[key])) {
|
|
315
|
-
for (var i = 0, max = query[key].length; i < max; i++) {
|
|
316
|
-
var value = query[key][i];
|
|
317
|
-
tmp += key;
|
|
318
|
-
tmp += this._querySuffixes[key] || '';
|
|
319
|
-
tmp += '=' + value;
|
|
320
|
-
tmp += this._querySeparator;
|
|
321
|
-
}
|
|
322
|
-
} else {
|
|
323
|
-
tmp += key;
|
|
324
|
-
|
|
325
|
-
if (query[key]) {
|
|
326
|
-
tmp += '=' + query[key];
|
|
327
|
-
} else if (query[key] === '') {
|
|
328
|
-
tmp += '=';
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
tmp += this._querySeparator;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
url += tmp.substring(0, tmp.length - 1);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (url == '?') {
|
|
340
|
-
url = '';
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return url;
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Sets method of communicating with a service
|
|
348
|
-
* @method
|
|
349
|
-
* @param {String} method
|
|
350
|
-
* @returns {Request}
|
|
351
|
-
*/
|
|
352
|
-
Request.prototype.setMethod = function (method) {
|
|
353
|
-
this._method = method;
|
|
354
|
-
return this;
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Returns method of communicating with a service
|
|
359
|
-
* @method
|
|
360
|
-
* @returns {String}
|
|
361
|
-
*/
|
|
362
|
-
Request.prototype.getMethod = function () {
|
|
363
|
-
return this._method;
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Sets connection host
|
|
368
|
-
* @method
|
|
369
|
-
* @param {String} host
|
|
370
|
-
* @returns {Request}
|
|
371
|
-
*/
|
|
372
|
-
Request.prototype.setConnectionHost = function (host) {
|
|
373
|
-
this._url = null;
|
|
374
|
-
if (host) {
|
|
375
|
-
this._host = host.toLowerCase();
|
|
376
|
-
} else {
|
|
377
|
-
this._host = host;
|
|
378
|
-
}
|
|
379
|
-
return this;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Returns connection host
|
|
384
|
-
* @method
|
|
385
|
-
* @returns {String}
|
|
386
|
-
*/
|
|
387
|
-
Request.prototype.getConnectionHost = function () {
|
|
388
|
-
if (this._host) {
|
|
389
|
-
return this._host.toLowerCase();
|
|
390
|
-
} else {
|
|
391
|
-
return this._host;
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Sets Host http header
|
|
398
|
-
* @method
|
|
399
|
-
* @param {String} host
|
|
400
|
-
* @returns {Request}
|
|
401
|
-
*/
|
|
402
|
-
Request.prototype.setHost = function (host) {
|
|
403
|
-
this._url = null;
|
|
404
|
-
|
|
405
|
-
if (host) {
|
|
406
|
-
this.headers.setHeader('host', host.toLowerCase(), true);
|
|
407
|
-
} else {
|
|
408
|
-
this.headers.setHeader('host', host, true);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return this;
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Returns Host http header
|
|
416
|
-
* @method
|
|
417
|
-
* @returns {String|null}
|
|
418
|
-
*/
|
|
419
|
-
Request.prototype.getHost = function () {
|
|
420
|
-
var host = this.headers.getHeader('host');
|
|
421
|
-
if (host) {
|
|
422
|
-
return host.toLowerCase();
|
|
423
|
-
} else {
|
|
424
|
-
return host;
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Sets connection port
|
|
430
|
-
* @method
|
|
431
|
-
* @param {Number} port
|
|
432
|
-
* @returns {Request}
|
|
433
|
-
*/
|
|
434
|
-
Request.prototype.setPort = function (port) {
|
|
435
|
-
this._url = null;
|
|
436
|
-
this._port = port;
|
|
437
|
-
return this;
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Returns connection port
|
|
442
|
-
* @method
|
|
443
|
-
* @returns {Number|null}
|
|
444
|
-
*/
|
|
445
|
-
Request.prototype.getPort = function () {
|
|
446
|
-
return this._port;
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Sets url path
|
|
451
|
-
* @method
|
|
452
|
-
* @param {String} path
|
|
453
|
-
* @returns {Request}
|
|
454
|
-
*/
|
|
455
|
-
Request.prototype.setPath = function (path) {
|
|
456
|
-
this._url = null;
|
|
457
|
-
this._path = path;
|
|
458
|
-
return this;
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Returns url path
|
|
463
|
-
* @method
|
|
464
|
-
* @returns {String|null}
|
|
465
|
-
*/
|
|
466
|
-
Request.prototype.getPath = function () {
|
|
467
|
-
return this._path;
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Sets protocol
|
|
472
|
-
* @method
|
|
473
|
-
* @param {String} proto
|
|
474
|
-
* @returns {Request}
|
|
475
|
-
*/
|
|
476
|
-
Request.prototype.setProto = function (proto) {
|
|
477
|
-
this._url = null;
|
|
478
|
-
this._proto = proto;
|
|
479
|
-
|
|
480
|
-
if (!this._defaultPortChanged) {
|
|
481
|
-
if (proto === 'https:') {
|
|
482
|
-
this.setPort(443);
|
|
483
|
-
} else if (proto === 'http:') {
|
|
484
|
-
this.setPort(80);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
return this;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Returns protocol
|
|
493
|
-
* @method
|
|
494
|
-
* @returns {String|null}
|
|
495
|
-
*/
|
|
496
|
-
Request.prototype.getProto = function () {
|
|
497
|
-
return this._proto;
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Sets http simple auth digest in format: user:pass
|
|
502
|
-
* @method
|
|
503
|
-
* @param {String} auth
|
|
504
|
-
* @returns {Request}
|
|
505
|
-
*/
|
|
506
|
-
Request.prototype.setAuth = function (auth) {
|
|
507
|
-
this._url = null;
|
|
508
|
-
|
|
509
|
-
var data;
|
|
510
|
-
|
|
511
|
-
if (Types.isString(auth)) {
|
|
512
|
-
var tmp = auth.split(':');
|
|
513
|
-
data = {
|
|
514
|
-
user: tmp[0],
|
|
515
|
-
password: tmp[1]
|
|
516
|
-
};
|
|
517
|
-
} else {
|
|
518
|
-
data = auth;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
this.setAuthUser(data.user);
|
|
522
|
-
this.setAuthPassword(data.password);
|
|
523
|
-
|
|
524
|
-
return this;
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Returns http simple auth digest in format: user:pass
|
|
529
|
-
* @method
|
|
530
|
-
* @returns {String|null}
|
|
531
|
-
*/
|
|
532
|
-
Request.prototype.getAuth = function () {
|
|
533
|
-
var user = this.getAuthUser(),
|
|
534
|
-
password = this.getAuthPassword();
|
|
535
|
-
if (user && password) {
|
|
536
|
-
return user + ':' + password;
|
|
537
|
-
}
|
|
538
|
-
return null;
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* Sets username for http simple auth digest
|
|
543
|
-
* @method
|
|
544
|
-
* @param {String} user
|
|
545
|
-
* @returns {Request}
|
|
546
|
-
*/
|
|
547
|
-
Request.prototype.setAuthUser = function (user) {
|
|
548
|
-
this._url = null;
|
|
549
|
-
this._authUser = user;
|
|
550
|
-
return this;
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Returns username for http simple auth digest
|
|
555
|
-
* @method
|
|
556
|
-
* @returns {String|null}
|
|
557
|
-
*/
|
|
558
|
-
Request.prototype.getAuthUser = function () {
|
|
559
|
-
return this._authUser;
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Sets password for http simple auth digest
|
|
564
|
-
* @method
|
|
565
|
-
* @param {String} password
|
|
566
|
-
* @returns {Request}
|
|
567
|
-
*/
|
|
568
|
-
Request.prototype.setAuthPassword = function (password) {
|
|
569
|
-
this._url = null;
|
|
570
|
-
this._authPassword = password;
|
|
571
|
-
return this;
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Returns password for http simple auth digest
|
|
576
|
-
* @method
|
|
577
|
-
* @returns {String|null}
|
|
578
|
-
*/
|
|
579
|
-
Request.prototype.getAuthPassword = function () {
|
|
580
|
-
return this._authPassword;
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* Sets url query string
|
|
585
|
-
* @method
|
|
586
|
-
* @param {String} query
|
|
587
|
-
* @returns {Request}
|
|
588
|
-
*/
|
|
589
|
-
Request.prototype.setQuery = function (query) {
|
|
590
|
-
this._url = null;
|
|
591
|
-
this._search = null;
|
|
592
|
-
this._query = query;
|
|
593
|
-
return this;
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Returns url query string
|
|
598
|
-
* @method
|
|
599
|
-
* @returns {String|null}
|
|
600
|
-
*/
|
|
601
|
-
Request.prototype.getQuery = function () {
|
|
602
|
-
return this._query;
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Sets url query component
|
|
607
|
-
* @param {String} name
|
|
608
|
-
* @param {String} value
|
|
609
|
-
* @returns {Request}
|
|
610
|
-
* @method
|
|
611
|
-
*/
|
|
612
|
-
Request.prototype.setQueryParam = function (name, value) {
|
|
613
|
-
this._url = null;
|
|
614
|
-
this._search = null;
|
|
615
|
-
if (!this._query) {
|
|
616
|
-
this._query = {};
|
|
617
|
-
}
|
|
618
|
-
this._query[name] = value;
|
|
619
|
-
|
|
620
|
-
if (Types.isArray(value)) {
|
|
621
|
-
this._querySuffixes[name] = '[]';
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
return this;
|
|
625
|
-
};
|
|
626
|
-
Request.prototype.hasQueryParam = function (name) {
|
|
627
|
-
if (!this._query) {
|
|
628
|
-
return false;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
return this._query.hasOwnProperty(name);
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Returns url query component
|
|
637
|
-
* @method
|
|
638
|
-
* @param {String} name
|
|
639
|
-
* @returns {String|null}
|
|
640
|
-
*/
|
|
641
|
-
Request.prototype.getQueryParam = function (name) {
|
|
642
|
-
if (!this._query) {
|
|
643
|
-
return null;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
if (this._query.hasOwnProperty(name)) {
|
|
647
|
-
// FIXME remove in next majaor
|
|
648
|
-
if (this._query[name] === null) {
|
|
649
|
-
return '';
|
|
650
|
-
}
|
|
651
|
-
/// END
|
|
652
|
-
|
|
653
|
-
return this._query[name];
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return null;
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Returns client ip address
|
|
661
|
-
* @method
|
|
662
|
-
* @returns {String|null}
|
|
663
|
-
*/
|
|
664
|
-
Request.prototype.getClientAddress = function () {
|
|
665
|
-
return (this._clientAddress || null);
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* Returns client port number
|
|
670
|
-
* @method
|
|
671
|
-
* @returns {Number|null}
|
|
672
|
-
*/
|
|
673
|
-
Request.prototype.getClientPort = function () {
|
|
674
|
-
return (this._clientPort || null);
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* Returns request processing time
|
|
679
|
-
* @method
|
|
680
|
-
* @returns {Number}
|
|
681
|
-
*/
|
|
682
|
-
Request.prototype.getProcessingTime = function () {
|
|
683
|
-
return this._timeStart ? (Date.now() - this._timeStart) : 0;
|
|
684
|
-
};
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* Sets request body (post data)
|
|
688
|
-
* @method
|
|
689
|
-
* @param {BinaryData|String|null|undefined} body
|
|
690
|
-
* @returns {Request}
|
|
691
|
-
*/
|
|
692
|
-
Request.prototype.setBody = function (body) {
|
|
693
|
-
if (Types.isInstanceOf(body, FormData)) {
|
|
694
|
-
this.setHeader('content-length', body.length(), true);
|
|
695
|
-
|
|
696
|
-
var boundary = body.getBoundary();
|
|
697
|
-
|
|
698
|
-
if (boundary) {
|
|
699
|
-
this.setHeader('content-type', 'multipart/form-data; boundary=' + boundary, true);
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
Message.prototype.setBody.call(this, body);
|
|
703
|
-
} else if (Types.isInstanceOf(body, BinaryData)) {
|
|
704
|
-
Message.prototype.setBody.call(this, body);
|
|
705
|
-
} else {
|
|
706
|
-
Message.prototype.setBody.call(this, new BinaryData(body ? body : '', BinaryData.Encoding.TEXT, BinaryData.CharacterEncoding.UTF8));
|
|
707
|
-
}
|
|
708
|
-
return this;
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Determines if caching is disabled
|
|
713
|
-
* @method
|
|
714
|
-
* @returns {Boolean}
|
|
715
|
-
*/
|
|
716
|
-
Request.prototype.isCachingDisabled = function () {
|
|
717
|
-
if (this.getMethod() == Request.POST) {
|
|
718
|
-
return true;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
return false;
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
* Determines if request is conditional (can return 304 response)
|
|
726
|
-
* @method
|
|
727
|
-
* @returns {Boolean}
|
|
728
|
-
*/
|
|
729
|
-
Request.prototype.isConditional = function () {
|
|
730
|
-
return this.getHeader('if-modified-since');
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* Determines if request client allow receiving compressed data
|
|
735
|
-
* @method
|
|
736
|
-
* @returns {Boolean}
|
|
737
|
-
*/
|
|
738
|
-
Request.prototype.isCompressedContentAccepted = function () {
|
|
739
|
-
var ae = this.getHeader('accept-encoding');
|
|
740
|
-
if (ae) {
|
|
741
|
-
return ae.indexOf('gzip') > -1;
|
|
742
|
-
}
|
|
743
|
-
return false;
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
/**
|
|
747
|
-
* Determines if client requests for regenerate content
|
|
748
|
-
* @method
|
|
749
|
-
* @returns {Boolean}
|
|
750
|
-
*/
|
|
751
|
-
Request.prototype.isGenerating = function () {
|
|
752
|
-
return this.getHeader('x-onet-regenerate');
|
|
753
|
-
};
|
|
754
|
-
|
|
755
|
-
/**
|
|
756
|
-
* Returns JSON representation of a request
|
|
757
|
-
* @method
|
|
758
|
-
* @returns {Object}
|
|
759
|
-
*/
|
|
760
|
-
Request.prototype.toJson = function () {
|
|
761
|
-
var body = this.getBody();
|
|
762
|
-
return {
|
|
763
|
-
"url": this.getUrl(),
|
|
764
|
-
"method": this._method,
|
|
765
|
-
"headers": this.headers.getHeaders(),
|
|
766
|
-
"body": body ? body.toString() : body,
|
|
767
|
-
"httpVersion": this._httpVersion
|
|
768
|
-
};
|
|
769
|
-
};
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* @constant
|
|
773
|
-
* @type {String}
|
|
774
|
-
* @default
|
|
775
|
-
*/
|
|
776
|
-
Request.OPTIONS = "OPTIONS";
|
|
777
|
-
/**
|
|
778
|
-
* @constant
|
|
779
|
-
* @type {String}
|
|
780
|
-
* @default
|
|
781
|
-
*/
|
|
782
|
-
Request.GET = "GET";
|
|
783
|
-
/**
|
|
784
|
-
* @constant
|
|
785
|
-
* @type {String}
|
|
786
|
-
* @default
|
|
787
|
-
*/
|
|
788
|
-
Request.HEAD = "HEAD";
|
|
789
|
-
/**
|
|
790
|
-
* @constant
|
|
791
|
-
* @type {String}
|
|
792
|
-
* @default
|
|
793
|
-
*/
|
|
794
|
-
Request.POST = "POST";
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* @constant
|
|
798
|
-
* @type {String}
|
|
799
|
-
* @default
|
|
800
|
-
*/
|
|
801
|
-
Request.PUT = "PUT";
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* @constant
|
|
805
|
-
* @type {String}
|
|
806
|
-
* @default
|
|
807
|
-
*/
|
|
808
|
-
Request.DELETE = "DELETE";
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* @constant
|
|
812
|
-
* @type {String}
|
|
813
|
-
* @default
|
|
814
|
-
*/
|
|
815
|
-
Request.TRACE = "TRACE";
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* @constant
|
|
819
|
-
* @type {String}
|
|
820
|
-
* @default
|
|
821
|
-
*/
|
|
822
|
-
Request.CONNECT = "CONNECT";
|
|
823
|
-
|
|
824
|
-
/**
|
|
825
|
-
* @static
|
|
826
|
-
* @constant
|
|
827
|
-
* @namespace
|
|
828
|
-
*/
|
|
829
|
-
Request.Exception = {};
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* @static
|
|
833
|
-
* @constant
|
|
834
|
-
* @type {String}
|
|
835
|
-
* @default
|
|
836
|
-
*/
|
|
837
|
-
Request.Exception.WRONG_BODY = "Body has to be a instance of BinaryData";
|
|
838
|
-
|
|
839
|
-
/**
|
|
840
|
-
* @static
|
|
841
|
-
* @constant
|
|
842
|
-
* @type {String}
|
|
843
|
-
* @default
|
|
844
|
-
*/
|
|
845
|
-
Request.Exception.REQUEST_CANNOT_BE_A_BUFFER = "Request cannot be a Buffer";
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
exports.Request = Request;
|