happy-dom 7.7.1 → 7.8.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.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/README.md +62 -27
- package/lib/async-task-manager/AsyncTaskManager.d.ts +3 -8
- package/lib/async-task-manager/AsyncTaskManager.js +21 -24
- package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
- package/lib/cookie/Cookie.d.ts +53 -0
- package/lib/cookie/Cookie.js +146 -0
- package/lib/cookie/Cookie.js.map +1 -0
- package/lib/cookie/CookieJar.d.ts +30 -0
- package/lib/cookie/CookieJar.js +84 -0
- package/lib/cookie/CookieJar.js.map +1 -0
- package/lib/event/IEventListener.d.ts +1 -1
- package/lib/exception/DOMExceptionNameEnum.d.ts +4 -1
- package/lib/exception/DOMExceptionNameEnum.js +3 -0
- package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
- package/lib/fetch/FetchHandler.d.ts +3 -2
- package/lib/fetch/FetchHandler.js +31 -3
- package/lib/fetch/FetchHandler.js.map +1 -1
- package/lib/fetch/RequestInfo.d.ts +5 -0
- package/lib/fetch/RequestInfo.js +3 -0
- package/lib/fetch/RequestInfo.js.map +1 -0
- package/lib/fetch/ResourceFetchHandler.d.ts +2 -2
- package/lib/fetch/ResourceFetchHandler.js +9 -8
- package/lib/fetch/ResourceFetchHandler.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +3 -4
- package/lib/index.js.map +1 -1
- package/lib/location/Location.d.ts +2 -1
- package/lib/location/Location.js +4 -7
- package/lib/location/Location.js.map +1 -1
- package/lib/location/RelativeURL.d.ts +3 -1
- package/lib/location/RelativeURL.js +2 -11
- package/lib/location/RelativeURL.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +14 -3
- package/lib/nodes/document/Document.js +21 -6
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +2 -0
- package/lib/nodes/html-link-element/HTMLLinkElement.js +5 -2
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-script-element/ScriptUtility.js +4 -0
- package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
- package/lib/window/IHappyDOMSettings.d.ts +9 -0
- package/lib/window/IHappyDOMSettings.js +3 -0
- package/lib/window/IHappyDOMSettings.js.map +1 -0
- package/lib/window/IWindow.d.ts +15 -6
- package/lib/window/Window.d.ts +18 -3
- package/lib/window/Window.js +26 -4
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-http-request/XMLHttpRequest.d.ts +196 -0
- package/lib/xml-http-request/XMLHttpRequest.js +777 -0
- package/lib/xml-http-request/XMLHttpRequest.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestCertificate.d.ts +5 -0
- package/lib/xml-http-request/XMLHttpRequestCertificate.js +55 -0
- package/lib/xml-http-request/XMLHttpRequestCertificate.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestEventTarget.d.ts +15 -0
- package/lib/xml-http-request/XMLHttpRequestEventTarget.js +23 -0
- package/lib/xml-http-request/XMLHttpRequestEventTarget.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestReadyStateEnum.d.ts +8 -0
- package/lib/xml-http-request/XMLHttpRequestReadyStateEnum.js +12 -0
- package/lib/xml-http-request/XMLHttpRequestReadyStateEnum.js.map +1 -0
- package/lib/xml-http-request/XMLHttpRequestUpload.d.ts +6 -0
- package/lib/xml-http-request/XMLHttpRequestUpload.js +13 -0
- package/lib/xml-http-request/XMLHttpRequestUpload.js.map +1 -0
- package/lib/xml-http-request/XMLHttpResponseTypeEnum.d.ts +8 -0
- package/lib/xml-http-request/XMLHttpResponseTypeEnum.js +12 -0
- package/lib/xml-http-request/XMLHttpResponseTypeEnum.js.map +1 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.d.ts +15 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.js +55 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.js.map +1 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestURLUtility.d.ts +35 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestURLUtility.js +62 -0
- package/lib/xml-http-request/utilities/XMLHttpRequestURLUtility.js.map +1 -0
- package/package.json +2 -2
- package/src/async-task-manager/AsyncTaskManager.ts +24 -26
- package/src/cookie/Cookie.ts +158 -0
- package/src/cookie/CookieJar.ts +82 -0
- package/src/event/IEventListener.ts +1 -1
- package/src/exception/DOMExceptionNameEnum.ts +4 -1
- package/src/fetch/FetchHandler.ts +40 -4
- package/src/fetch/RequestInfo.ts +6 -0
- package/src/fetch/ResourceFetchHandler.ts +10 -8
- package/src/index.ts +1 -2
- package/src/location/Location.ts +3 -3
- package/src/location/RelativeURL.ts +3 -14
- package/src/nodes/document/Document.ts +24 -6
- package/src/nodes/document/IDocument.ts +2 -0
- package/src/nodes/html-link-element/HTMLLinkElement.ts +7 -2
- package/src/nodes/html-script-element/HTMLScriptElement.ts +1 -1
- package/src/nodes/html-script-element/ScriptUtility.ts +8 -0
- package/src/window/IHappyDOMSettings.ts +9 -0
- package/src/window/IWindow.ts +15 -6
- package/src/window/Window.ts +36 -5
- package/src/xml-http-request/XMLHttpRequest.ts +998 -0
- package/src/xml-http-request/XMLHttpRequestCertificate.ts +52 -0
- package/src/xml-http-request/XMLHttpRequestEventTarget.ts +17 -0
- package/src/xml-http-request/XMLHttpRequestReadyStateEnum.ts +9 -0
- package/src/xml-http-request/XMLHttpRequestUpload.ts +6 -0
- package/src/xml-http-request/XMLHttpResponseTypeEnum.ts +9 -0
- package/src/xml-http-request/utilities/XMLHttpRequestSyncRequestScriptBuilder.ts +53 -0
- package/src/xml-http-request/utilities/XMLHttpRequestURLUtility.ts +64 -0
- package/lib/cookie/CookieUtility.d.ts +0 -15
- package/lib/cookie/CookieUtility.js +0 -83
- package/lib/cookie/CookieUtility.js.map +0 -1
- package/lib/location/URL.d.ts +0 -53
- package/lib/location/URL.js +0 -96
- package/lib/location/URL.js.map +0 -1
- package/src/cookie/CookieUtility.ts +0 -87
- package/src/location/URL.ts +0 -102
@@ -0,0 +1,52 @@
|
|
1
|
+
// SSL certificate generated for Happy DOM to be able to perform HTTPS requests
|
2
|
+
export default {
|
3
|
+
cert: `-----BEGIN CERTIFICATE-----
|
4
|
+
MIIDYzCCAkugAwIBAgIUJRKB/H66hpet1VfUlm0CiXqePA4wDQYJKoZIhvcNAQEL
|
5
|
+
BQAwQTELMAkGA1UEBhMCU0UxDjAMBgNVBAgMBVNrYW5lMQ4wDAYDVQQHDAVNYWxt
|
6
|
+
bzESMBAGA1UECgwJSGFwcHkgRE9NMB4XDTIyMTAxMTIyMDM0OVoXDTMyMTAwODIy
|
7
|
+
MDM0OVowQTELMAkGA1UEBhMCU0UxDjAMBgNVBAgMBVNrYW5lMQ4wDAYDVQQHDAVN
|
8
|
+
YWxtbzESMBAGA1UECgwJSGFwcHkgRE9NMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
|
9
|
+
MIIBCgKCAQEAqerQSQEg/SxVxRiwlItithr5e5EMZo1nsqt/xOxagbmpW3IEmt0j
|
10
|
+
bpbH7iEF4DDEo7KAOwUCOwVWeFxRoag8lG2ax48wrgjlCna45XDn0Xeg1ARajL04
|
11
|
+
gs46HZ0VrzIloVGfln0zgt/Vum5BNqs9Oc5fQoBmoP3cAn3dn4ZVcP0AKthtcyPl
|
12
|
+
q2DuNRN0PV0D2RtMSiAy9l1Ko6N5x+sAeClDyOL+sTDLngZBVeZyOKt9Id15S8Zt
|
13
|
+
XtA6VMgHnnF3jChn7pag77rsd/y5iANAVNZYqRl+Eg7xaDcsvbgH46UBOrBcB39Q
|
14
|
+
tTh5Mtjoxep5e3ZDFG+kQ1HUE+iz5O5n0wIDAQABo1MwUTAdB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ls8by3yFsL
|
46
|
+
PQwERa/0jfCl1M6kb9XQNpQa2pw6ANUsWKTDpUJn2wZ+9N3F1RaDwzMWyH5lRVmK
|
47
|
+
M0qoTfdjpSg5Jwgd75taWt4bxGJWeflSSv8z5R0BAoGAWL8c527AbeBvx2tOYKkD
|
48
|
+
2TFranvANNcoMrbeviZSkkGvMNDP3p8b6juJwXOIeWNr8q4vFgCzLmq6d1/9gYm2
|
49
|
+
3XJwwyD0LKlqzkBrrKU47qrnmMosUrIRlrAzd3HbShOptxc6Iz2apSaUDKGKXkaw
|
50
|
+
gl5OpEjeliU7Mus0BVS858g=
|
51
|
+
-----END PRIVATE KEY-----`
|
52
|
+
};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import ProgressEvent from '../event/events/ProgressEvent';
|
2
|
+
import EventTarget from '../event/EventTarget';
|
3
|
+
|
4
|
+
export type ProgressEventListener = (event: ProgressEvent) => void;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* References: https://xhr.spec.whatwg.org/#xmlhttprequesteventtarget.
|
8
|
+
*/
|
9
|
+
export default class XMLHttpRequestEventTarget extends EventTarget {
|
10
|
+
public onloadstart: ProgressEventListener | null = null;
|
11
|
+
public onprogress: ProgressEventListener | null = null;
|
12
|
+
public onabort: (event: ProgressEvent) => void | null = null;
|
13
|
+
public onerror: ProgressEventListener | null = null;
|
14
|
+
public onload: ProgressEventListener | null = null;
|
15
|
+
public ontimeout: ProgressEventListener | null = null;
|
16
|
+
public onloadend: ProgressEventListener | null = null;
|
17
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import HTTPS from 'https';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Synchroneous XMLHttpRequest script builder.
|
5
|
+
*/
|
6
|
+
export default class XMLHttpRequestSyncRequestScriptBuilder {
|
7
|
+
/**
|
8
|
+
* Sends a synchronous request.
|
9
|
+
*
|
10
|
+
* @param options Options.
|
11
|
+
* @param ssl SSL.
|
12
|
+
* @param data Data.
|
13
|
+
*/
|
14
|
+
public static getScript(options: HTTPS.RequestOptions, ssl: boolean, data?: string): string {
|
15
|
+
// Synchronous
|
16
|
+
// Note: console.log === stdout
|
17
|
+
// The async request the other Node process executes
|
18
|
+
return `
|
19
|
+
const HTTP = require('http');
|
20
|
+
const HTTPS = require('https');
|
21
|
+
const sendRequest = HTTP${ssl ? 'S' : ''}.request;
|
22
|
+
const options = ${JSON.stringify(options)};
|
23
|
+
const request = sendRequest(options, (response) => {
|
24
|
+
let responseText = '';
|
25
|
+
let responseData = Buffer.alloc(0);
|
26
|
+
response.setEncoding('utf8');
|
27
|
+
response.on('data', (chunk) => {
|
28
|
+
responseText += chunk;
|
29
|
+
responseData = Buffer.concat([responseData, Buffer.from(chunk)]);
|
30
|
+
});
|
31
|
+
response.on('end', () => {
|
32
|
+
console.log(JSON.stringify({
|
33
|
+
error: null,
|
34
|
+
data: {
|
35
|
+
statusCode: response.statusCode,
|
36
|
+
statusMessage: response.statusMessage,
|
37
|
+
headers: response.headers,
|
38
|
+
text: responseText,
|
39
|
+
data: responseData.toString('base64')
|
40
|
+
}
|
41
|
+
}));
|
42
|
+
});
|
43
|
+
response.on('error', (error) => {
|
44
|
+
console.log(JSON.stringify({ error: error.toString(), data: null }));
|
45
|
+
});
|
46
|
+
});
|
47
|
+
request.write(\`${JSON.stringify(data ?? '')
|
48
|
+
.slice(1, -1)
|
49
|
+
.replace(/'/g, "\\'")}\`);
|
50
|
+
request.end();
|
51
|
+
`;
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { URL } from 'url';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* URL utility.
|
5
|
+
*/
|
6
|
+
export default class XMLHttpRequestURLUtility {
|
7
|
+
/**
|
8
|
+
* Returns "true" if SSL.
|
9
|
+
*
|
10
|
+
* @param url URL.
|
11
|
+
* @returns "true" if SSL.
|
12
|
+
*/
|
13
|
+
public static isSSL(url: URL): boolean {
|
14
|
+
return url.protocol === 'https:';
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Returns "true" if SSL.
|
19
|
+
*
|
20
|
+
* @param url URL.
|
21
|
+
* @returns "true" if SSL.
|
22
|
+
*/
|
23
|
+
public static isLocal(url: URL): boolean {
|
24
|
+
return url.protocol === 'file:';
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Returns "true" if protocol is valid.
|
29
|
+
*
|
30
|
+
* @param url URL.
|
31
|
+
* @returns "true" if valid.
|
32
|
+
*/
|
33
|
+
public static isSupportedProtocol(url: URL): boolean {
|
34
|
+
switch (url.protocol) {
|
35
|
+
case 'https:':
|
36
|
+
case 'http:':
|
37
|
+
case 'file:':
|
38
|
+
case undefined:
|
39
|
+
case '':
|
40
|
+
return true;
|
41
|
+
}
|
42
|
+
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Returns host.
|
48
|
+
*
|
49
|
+
* @param url URL.
|
50
|
+
* @returns Host.
|
51
|
+
*/
|
52
|
+
public static getHost(url: URL): string {
|
53
|
+
switch (url.protocol) {
|
54
|
+
case 'http:':
|
55
|
+
case 'https:':
|
56
|
+
return url.hostname;
|
57
|
+
case undefined:
|
58
|
+
case '':
|
59
|
+
return 'localhost';
|
60
|
+
default:
|
61
|
+
return null;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import Location from '../location/Location';
|
2
|
-
/**
|
3
|
-
* Cookie utility.
|
4
|
-
*/
|
5
|
-
export default class CookieUtility {
|
6
|
-
/**
|
7
|
-
* Returns a cookie string.
|
8
|
-
*
|
9
|
-
* @param location Location.
|
10
|
-
* @param cookies Current cookie string.
|
11
|
-
* @param newCookie New cookie string.
|
12
|
-
* @returns Generated cookie string.
|
13
|
-
*/
|
14
|
-
static getCookieString(location: Location, cookies: string, newCookie: any): string;
|
15
|
-
}
|
@@ -1,83 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
/**
|
4
|
-
* Cookie utility.
|
5
|
-
*/
|
6
|
-
class CookieUtility {
|
7
|
-
/**
|
8
|
-
* Returns a cookie string.
|
9
|
-
*
|
10
|
-
* @param location Location.
|
11
|
-
* @param cookies Current cookie string.
|
12
|
-
* @param newCookie New cookie string.
|
13
|
-
* @returns Generated cookie string.
|
14
|
-
*/
|
15
|
-
static getCookieString(location, cookies, newCookie) {
|
16
|
-
const newCookieParts = newCookie.split(';');
|
17
|
-
const [newCookieName, newCookieValue] = newCookieParts.shift().trim().split('=');
|
18
|
-
let isExpired = false;
|
19
|
-
for (const part of newCookieParts) {
|
20
|
-
const [key, value] = part.trim().split('=');
|
21
|
-
switch (key.toLowerCase()) {
|
22
|
-
case 'expires':
|
23
|
-
const expires = new Date(value).getTime();
|
24
|
-
const now = Date.now();
|
25
|
-
if (expires < now) {
|
26
|
-
isExpired = true;
|
27
|
-
break;
|
28
|
-
}
|
29
|
-
break;
|
30
|
-
case 'domain':
|
31
|
-
const hostnameParts = location.hostname.split('.');
|
32
|
-
if (hostnameParts.length > 2) {
|
33
|
-
hostnameParts.shift();
|
34
|
-
}
|
35
|
-
const currentDomain = hostnameParts.join('.');
|
36
|
-
if (!value.endsWith(currentDomain)) {
|
37
|
-
return cookies;
|
38
|
-
}
|
39
|
-
break;
|
40
|
-
case 'path':
|
41
|
-
const pathname = location.pathname;
|
42
|
-
const currentPath = pathname.startsWith('/') ? pathname.replace('/', '') : pathname;
|
43
|
-
const path = value.startsWith('/') ? value.replace('/', '') : value;
|
44
|
-
if (path && !currentPath.startsWith(path)) {
|
45
|
-
return cookies;
|
46
|
-
}
|
47
|
-
break;
|
48
|
-
case 'max-age':
|
49
|
-
if (parseInt(value) <= 0) {
|
50
|
-
return cookies;
|
51
|
-
}
|
52
|
-
break;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
const newCookies = [];
|
56
|
-
if (cookies) {
|
57
|
-
for (const cookie of cookies.split(';')) {
|
58
|
-
const [name, value] = cookie.trim().split('=');
|
59
|
-
if ((name && name !== newCookieName) ||
|
60
|
-
(!value && newCookieValue) ||
|
61
|
-
(value && !newCookieValue)) {
|
62
|
-
if (value) {
|
63
|
-
newCookies.push(`${name}=${value}`);
|
64
|
-
}
|
65
|
-
else {
|
66
|
-
newCookies.push(name);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
if (!isExpired) {
|
72
|
-
if (newCookieValue) {
|
73
|
-
newCookies.push(`${newCookieName}=${newCookieValue}`);
|
74
|
-
}
|
75
|
-
else {
|
76
|
-
newCookies.push(newCookieName);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
return newCookies.join('; ');
|
80
|
-
}
|
81
|
-
}
|
82
|
-
exports.default = CookieUtility;
|
83
|
-
//# sourceMappingURL=CookieUtility.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"CookieUtility.js","sourceRoot":"","sources":["../../src/cookie/CookieUtility.ts"],"names":[],"mappings":";;AAEA;;GAEG;AACH,MAAqB,aAAa;IACjC;;;;;;;OAOG;IACI,MAAM,CAAC,eAAe,CAAC,QAAkB,EAAE,OAAe,EAAE,SAAS;QAC3E,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjF,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE;YAClC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAE5C,QAAQ,GAAG,CAAC,WAAW,EAAE,EAAE;gBAC1B,KAAK,SAAS;oBACb,MAAM,OAAO,GAAG,IAAI,IAAI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AAC;QAEtB,IAAI,OAAO,EAAE;YACZ,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACxC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC/C,IACC,CAAC,IAAI,IAAI,IAAI,KAAK,aAAa,CAAC;oBAChC,CAAC,CAAC,KAAK,IAAI,cAAc,CAAC;oBAC1B,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,EACzB;oBACD,IAAI,KAAK,EAAE;wBACV,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;qBACpC;yBAAM;wBACN,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;qBACtB;iBACD;aACD;SACD;QAED,IAAI,CAAC,SAAS,EAAE;YACf,IAAI,cAAc,EAAE;gBACnB,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,IAAI,cAAc,EAAE,CAAC,CAAC;aACtD;iBAAM;gBACN,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAC/B;SACD;QAED,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACD;AAjFD,gCAiFC"}
|
package/lib/location/URL.d.ts
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
*
|
3
|
-
*/
|
4
|
-
export default class URL {
|
5
|
-
protocol: string;
|
6
|
-
hostname: string;
|
7
|
-
port: string;
|
8
|
-
pathname: string;
|
9
|
-
search: string;
|
10
|
-
hash: string;
|
11
|
-
username: string;
|
12
|
-
password: string;
|
13
|
-
/**
|
14
|
-
* Constructor.
|
15
|
-
*
|
16
|
-
* @param [url] URL.
|
17
|
-
*/
|
18
|
-
constructor(url?: string);
|
19
|
-
/**
|
20
|
-
* Returns the entire URL as a string.
|
21
|
-
*
|
22
|
-
* @returns Href.
|
23
|
-
*/
|
24
|
-
get href(): string;
|
25
|
-
/**
|
26
|
-
* Sets the href.
|
27
|
-
*
|
28
|
-
* @param url URL.
|
29
|
-
*/
|
30
|
-
set href(url: string);
|
31
|
-
/**
|
32
|
-
* Returns the origin.
|
33
|
-
*
|
34
|
-
* @returns HREF.
|
35
|
-
*/
|
36
|
-
get origin(): string;
|
37
|
-
/**
|
38
|
-
* Returns the entire URL as a string.
|
39
|
-
*
|
40
|
-
* @returns Host.
|
41
|
-
*/
|
42
|
-
get host(): string;
|
43
|
-
/**
|
44
|
-
* Returns the entire URL as a string.
|
45
|
-
*/
|
46
|
-
toString(): string;
|
47
|
-
/**
|
48
|
-
* Parses an URL.
|
49
|
-
*
|
50
|
-
* @param url URL.
|
51
|
-
*/
|
52
|
-
protected parse(url: string): void;
|
53
|
-
}
|
package/lib/location/URL.js
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const URL_REGEXP = /(https?:)\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
|
4
|
-
const PATH_REGEXP = /([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
|
5
|
-
/**
|
6
|
-
*
|
7
|
-
*/
|
8
|
-
class URL {
|
9
|
-
/**
|
10
|
-
* Constructor.
|
11
|
-
*
|
12
|
-
* @param [url] URL.
|
13
|
-
*/
|
14
|
-
constructor(url) {
|
15
|
-
this.protocol = '';
|
16
|
-
this.hostname = '';
|
17
|
-
this.port = '';
|
18
|
-
this.pathname = '';
|
19
|
-
this.search = '';
|
20
|
-
this.hash = '';
|
21
|
-
this.username = '';
|
22
|
-
this.password = '';
|
23
|
-
if (url) {
|
24
|
-
this.parse(url);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Returns the entire URL as a string.
|
29
|
-
*
|
30
|
-
* @returns Href.
|
31
|
-
*/
|
32
|
-
get href() {
|
33
|
-
const credentials = this.username ? `${this.username}:${this.password}@` : '';
|
34
|
-
return this.protocol + '//' + credentials + this.host + this.pathname + this.search + this.hash;
|
35
|
-
}
|
36
|
-
/**
|
37
|
-
* Sets the href.
|
38
|
-
*
|
39
|
-
* @param url URL.
|
40
|
-
*/
|
41
|
-
set href(url) {
|
42
|
-
this.parse(url);
|
43
|
-
}
|
44
|
-
/**
|
45
|
-
* Returns the origin.
|
46
|
-
*
|
47
|
-
* @returns HREF.
|
48
|
-
*/
|
49
|
-
get origin() {
|
50
|
-
return this.protocol + '//' + this.host;
|
51
|
-
}
|
52
|
-
/**
|
53
|
-
* Returns the entire URL as a string.
|
54
|
-
*
|
55
|
-
* @returns Host.
|
56
|
-
*/
|
57
|
-
get host() {
|
58
|
-
return this.hostname + this.port;
|
59
|
-
}
|
60
|
-
/**
|
61
|
-
* Returns the entire URL as a string.
|
62
|
-
*/
|
63
|
-
toString() {
|
64
|
-
return this.href;
|
65
|
-
}
|
66
|
-
/**
|
67
|
-
* Parses an URL.
|
68
|
-
*
|
69
|
-
* @param url URL.
|
70
|
-
*/
|
71
|
-
parse(url) {
|
72
|
-
const match = url.match(URL_REGEXP);
|
73
|
-
if (match) {
|
74
|
-
const hostnamePart = match[2] ? match[2].split('@') : '';
|
75
|
-
const credentialsPart = hostnamePart.length > 1 ? hostnamePart[0].split(':') : null;
|
76
|
-
this.protocol = match[1] || '';
|
77
|
-
this.hostname = hostnamePart.length > 1 ? hostnamePart[1] : hostnamePart[0];
|
78
|
-
this.port = match[3] || '';
|
79
|
-
this.pathname = match[4] || '/';
|
80
|
-
this.search = match[5] || '';
|
81
|
-
this.hash = match[6] || '';
|
82
|
-
this.username = credentialsPart ? credentialsPart[0] : '';
|
83
|
-
this.password = credentialsPart ? credentialsPart[1] : '';
|
84
|
-
}
|
85
|
-
else {
|
86
|
-
const pathMatch = url.match(PATH_REGEXP);
|
87
|
-
if (pathMatch) {
|
88
|
-
this.pathname = pathMatch[1] || '';
|
89
|
-
this.search = pathMatch[2] || '';
|
90
|
-
this.hash = pathMatch[3] || '';
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
}
|
95
|
-
exports.default = URL;
|
96
|
-
//# sourceMappingURL=URL.js.map
|
package/lib/location/URL.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"URL.js","sourceRoot":"","sources":["../../src/location/URL.ts"],"names":[],"mappings":";;AAAA,MAAM,UAAU,GACf,8GAA8G,CAAC;AAChH,MAAM,WAAW,GAAG,8CAA8C,CAAC;AAEnE;;GAEG;AACH,MAAqB,GAAG;IAUvB;;;;OAIG;IACH,YAAY,GAAY;QAdjB,aAAQ,GAAG,EAAE,CAAC;QACd,aAAQ,GAAG,EAAE,CAAC;QACd,SAAI,GAAG,EAAE,CAAC;QACV,aAAQ,GAAG,EAAE,CAAC;QACd,WAAM,GAAG,EAAE,CAAC;QACZ,SAAI,GAAG,EAAE,CAAC;QACV,aAAQ,GAAG,EAAE,CAAC;QACd,aAAQ,GAAG,EAAE,CAAC;QAQpB,IAAI,GAAG,EAAE;YACR,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAChB;IACF,CAAC;IAED;;;;OAIG;IACH,IAAW,IAAI;QACd,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,OAAO,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;IACjG,CAAC;IAED;;;;OAIG;IACH,IAAW,IAAI,CAAC,GAAW;QAC1B,IAAI,CAAC,K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C,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,IAAI,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D;aAAM;YACN,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACzC,IAAI,SAAS,EAAE;gBACd,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAC/B;SACD;IACF,CAAC;CACD;AA9FD,sBA8FC"}
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import Location from '../location/Location';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Cookie utility.
|
5
|
-
*/
|
6
|
-
export default class CookieUtility {
|
7
|
-
/**
|
8
|
-
* Returns a cookie string.
|
9
|
-
*
|
10
|
-
* @param location Location.
|
11
|
-
* @param cookies Current cookie string.
|
12
|
-
* @param newCookie New cookie string.
|
13
|
-
* @returns Generated cookie string.
|
14
|
-
*/
|
15
|
-
public static getCookieString(location: Location, cookies: string, newCookie): string {
|
16
|
-
const newCookieParts = newCookie.split(';');
|
17
|
-
const [newCookieName, newCookieValue] = newCookieParts.shift().trim().split('=');
|
18
|
-
let isExpired = false;
|
19
|
-
|
20
|
-
for (const part of newCookieParts) {
|
21
|
-
const [key, value] = part.trim().split('=');
|
22
|
-
|
23
|
-
switch (key.toLowerCase()) {
|
24
|
-
case 'expires':
|
25
|
-
const expires = new Date(value).getTime();
|
26
|
-
const now = Date.now();
|
27
|
-
if (expires < now) {
|
28
|
-
isExpired = true;
|
29
|
-
break;
|
30
|
-
}
|
31
|
-
break;
|
32
|
-
case 'domain':
|
33
|
-
const hostnameParts = location.hostname.split('.');
|
34
|
-
if (hostnameParts.length > 2) {
|
35
|
-
hostnameParts.shift();
|
36
|
-
}
|
37
|
-
const currentDomain = hostnameParts.join('.');
|
38
|
-
if (!value.endsWith(currentDomain)) {
|
39
|
-
return cookies;
|
40
|
-
}
|
41
|
-
break;
|
42
|
-
case 'path':
|
43
|
-
const pathname = location.pathname;
|
44
|
-
const currentPath = pathname.startsWith('/') ? pathname.replace('/', '') : pathname;
|
45
|
-
const path = value.startsWith('/') ? value.replace('/', '') : value;
|
46
|
-
if (path && !currentPath.startsWith(path)) {
|
47
|
-
return cookies;
|
48
|
-
}
|
49
|
-
break;
|
50
|
-
case 'max-age':
|
51
|
-
if (parseInt(value) <= 0) {
|
52
|
-
return cookies;
|
53
|
-
}
|
54
|
-
break;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
const newCookies = [];
|
59
|
-
|
60
|
-
if (cookies) {
|
61
|
-
for (const cookie of cookies.split(';')) {
|
62
|
-
const [name, value] = cookie.trim().split('=');
|
63
|
-
if (
|
64
|
-
(name && name !== newCookieName) ||
|
65
|
-
(!value && newCookieValue) ||
|
66
|
-
(value && !newCookieValue)
|
67
|
-
) {
|
68
|
-
if (value) {
|
69
|
-
newCookies.push(`${name}=${value}`);
|
70
|
-
} else {
|
71
|
-
newCookies.push(name);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
if (!isExpired) {
|
78
|
-
if (newCookieValue) {
|
79
|
-
newCookies.push(`${newCookieName}=${newCookieValue}`);
|
80
|
-
} else {
|
81
|
-
newCookies.push(newCookieName);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
return newCookies.join('; ');
|
86
|
-
}
|
87
|
-
}
|
package/src/location/URL.ts
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
const URL_REGEXP =
|
2
|
-
/(https?:)\/\/([-a-zA-Z0-9@:%._\+~#=]{2,256}[a-z]{2,6})(:[0-9]*)?([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
|
3
|
-
const PATH_REGEXP = /([-a-zA-Z0-9@:%_\+.~c&//=]*)(\?[^#]*)?(#.*)?/;
|
4
|
-
|
5
|
-
/**
|
6
|
-
*
|
7
|
-
*/
|
8
|
-
export default class URL {
|
9
|
-
public protocol = '';
|
10
|
-
public hostname = '';
|
11
|
-
public port = '';
|
12
|
-
public pathname = '';
|
13
|
-
public search = '';
|
14
|
-
public hash = '';
|
15
|
-
public username = '';
|
16
|
-
public password = '';
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Constructor.
|
20
|
-
*
|
21
|
-
* @param [url] URL.
|
22
|
-
*/
|
23
|
-
constructor(url?: string) {
|
24
|
-
if (url) {
|
25
|
-
this.parse(url);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
* Returns the entire URL as a string.
|
31
|
-
*
|
32
|
-
* @returns Href.
|
33
|
-
*/
|
34
|
-
public get href(): string {
|
35
|
-
const credentials = this.username ? `${this.username}:${this.password}@` : '';
|
36
|
-
return this.protocol + '//' + credentials + this.host + this.pathname + this.search + this.hash;
|
37
|
-
}
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Sets the href.
|
41
|
-
*
|
42
|
-
* @param url URL.
|
43
|
-
*/
|
44
|
-
public set href(url: string) {
|
45
|
-
this.parse(url);
|
46
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Returns the origin.
|
50
|
-
*
|
51
|
-
* @returns HREF.
|
52
|
-
*/
|
53
|
-
public get origin(): string {
|
54
|
-
return this.protocol + '//' + this.host;
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Returns the entire URL as a string.
|
59
|
-
*
|
60
|
-
* @returns Host.
|
61
|
-
*/
|
62
|
-
public get host(): string {
|
63
|
-
return this.hostname + this.port;
|
64
|
-
}
|
65
|
-
|
66
|
-
/**
|
67
|
-
* Returns the entire URL as a string.
|
68
|
-
*/
|
69
|
-
public toString(): string {
|
70
|
-
return this.href;
|
71
|
-
}
|
72
|
-
|
73
|
-
/**
|
74
|
-
* Parses an URL.
|
75
|
-
*
|
76
|
-
* @param url URL.
|
77
|
-
*/
|
78
|
-
protected parse(url: string): void {
|
79
|
-
const match = url.match(URL_REGEXP);
|
80
|
-
|
81
|
-
if (match) {
|
82
|
-
const hostnamePart = match[2] ? match[2].split('@') : '';
|
83
|
-
const credentialsPart = hostnamePart.length > 1 ? hostnamePart[0].split(':') : null;
|
84
|
-
|
85
|
-
this.protocol = match[1] || '';
|
86
|
-
this.hostname = hostnamePart.length > 1 ? hostnamePart[1] : hostnamePart[0];
|
87
|
-
this.port = match[3] || '';
|
88
|
-
this.pathname = match[4] || '/';
|
89
|
-
this.search = match[5] || '';
|
90
|
-
this.hash = match[6] || '';
|
91
|
-
this.username = credentialsPart ? credentialsPart[0] : '';
|
92
|
-
this.password = credentialsPart ? credentialsPart[1] : '';
|
93
|
-
} else {
|
94
|
-
const pathMatch = url.match(PATH_REGEXP);
|
95
|
-
if (pathMatch) {
|
96
|
-
this.pathname = pathMatch[1] || '';
|
97
|
-
this.search = pathMatch[2] || '';
|
98
|
-
this.hash = pathMatch[3] || '';
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|