Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#463@minor: Added partial support for XMLHttpRequest. #520

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
18b0bd6
#463@minor: Added partial support for XMLHttpRequest.
Mas0nShi Jun 25, 2022
3e67605
#514@patch: Fixes method getAbsoluteURL.
Mas0nShi Jun 26, 2022
30b4860
#463@minor: Continue added partial support for XMLHttpRequest.
Mas0nShi Jun 26, 2022
9d9b455
#463@minor: Continue added partial support for XMLHttpRequest.
Mas0nShi Jun 26, 2022
e01541e
#463@minor: Continue added partial support for XMLHttpRequest.
Mas0nShi Jun 26, 2022
4d5f54c
#522@patch: Fixes resource load error when websites enabled anti-thef…
Mas0nShi Jun 27, 2022
da34ce5
#463@minor: Continue added partial support for XMLHttpRequest.
Mas0nShi Jun 28, 2022
6fc77aa
Merge branch 'master' into 463-adds-support-for-xml-http-request
Mas0nShi Jul 1, 2022
d1f8256
#521@patch: Replace URL to native module URL.
Mas0nShi Jul 1, 2022
a1c0e81
#521@patch: Fixes test units error.
Mas0nShi Jul 1, 2022
9f9df58
#521@minor: Continue added partial support for XMLHttpRequest.
Mas0nShi Jul 1, 2022
a71819f
#526@minor: Adds support for Document.documentURI and Document.URL.
Mas0nShi Jul 1, 2022
1ff5b9a
#526@minor: Continue Adds support for XMLHttpRequest (Sync) and remov…
Mas0nShi Jul 3, 2022
bda8a93
#463@trivial: Continues on XMLHttpRequest implementation.
daveed07 Oct 11, 2022
fc8a845
#526@minor: Fixes problem.
Mas0nShi Oct 15, 2022
40cd3c1
#526@minor: Continue Fixes Problem.
Mas0nShi Oct 16, 2022
f517c8f
Merge remote-tracking branch 'origin/master' into 463-adds-support-fo…
Mas0nShi Oct 16, 2022
9cce579
#526@minor: Continue Fixes Problem.
Mas0nShi Oct 16, 2022
b72cdd9
#526@minor: Continue Fixes Problem.
Mas0nShi Oct 16, 2022
608b717
#526@minor: Continue Fixes Problem.
Mas0nShi Oct 16, 2022
855ed45
#463@minor: Continue Fixes Problem.
Mas0nShi Oct 16, 2022
aaf8673
#463@minor: Continue Fixes Problem.
Mas0nShi Oct 16, 2022
2ee990e
#463@minor: Found Bugs in CookieJar, add more support for syncRequest.
Mas0nShi Oct 16, 2022
7f55543
#463@minor: Found Bugs in CookieJar, add more support for syncRequest.
Mas0nShi Oct 16, 2022
d588d3b
#463@minor: Found Bugs in CookieJar, add more support for syncRequest.
Mas0nShi Oct 16, 2022
3431208
#463@minor: Continue Fixes.
Mas0nShi Oct 16, 2022
a4b22ea
#463@minor: Continue Fixes.
Mas0nShi Oct 16, 2022
f67f67d
#463@trivial: Disables HTTP request local filesystem by default and i…
daveed07 Oct 18, 2022
861690a
#463@trivial: Removes unused dependency.
capricorn86 Oct 18, 2022
9c23e1e
Merge branch 'master' into 463-adds-support-for-xml-http-request
Mas0nShi Oct 19, 2022
6f8d5dd
#520@minor: Fixes syntax error.
Mas0nShi Oct 20, 2022
3a7f974
#520@minor: Optimize the code.
Mas0nShi Oct 21, 2022
941450c
#520@minor: Optimize the code.
Mas0nShi Oct 21, 2022
1646f8e
#520@minor: Continue to improve XMLHttpRequest.
Mas0nShi Oct 22, 2022
a981b8b
Merge branch 'master' into 463-adds-support-for-xml-http-request
Mas0nShi Oct 25, 2022
677a376
#463@trivial: Continue on XMLHttpRequest implementation.
daveed07 Oct 26, 2022
9b0b6ea
#463@trivial: Continue on XMLHttpRequest implementation.
capricorn86 Nov 14, 2022
929fbd3
Merge branch 'capricorn86:master' into 463-adds-support-for-xml-http-…
Mas0nShi Nov 28, 2022
e7bb2bc
#463@trivial: Continues on XMLHttpRequest implementation.
capricorn86 Dec 3, 2022
ca00cb5
#463@trivial: Continues on XMLHttpRequest implementation.
capricorn86 Dec 5, 2022
b1b7493
Merge branch 'master' into 463-adds-support-for-xml-http-request
Mas0nShi Dec 6, 2022
96682af
#520@patch: Fixes cookie setting.
Mas0nShi Dec 6, 2022
b670ae6
#463@trivial: Continues on XMLHttpRequest implementation.
capricorn86 Dec 6, 2022
2193f38
#463@trivial: Continues on XMLHttpRequest implementation.
capricorn86 Dec 6, 2022
7bf4bd5
#463@trivial: Continues on XMLHttpRequest implementation.
capricorn86 Dec 7, 2022
2e45e3e
#463@trivial: Continues on XMLHttpRequest implementation.
capricorn86 Dec 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/happy-dom/src/exception/DOMExceptionNameEnum.ts
Expand Up @@ -3,6 +3,8 @@ enum DOMExceptionNameEnum {
indexSizeError = 'IndexSizeError',
syntaxError = 'SyntaxError',
hierarchyRequestError = 'HierarchyRequestError',
invalidCharacterError = 'InvalidCharacterError'
invalidCharacterError = 'InvalidCharacterError',
securityError = 'SecurityError',
networkError = 'NetworkError'
}
export default DOMExceptionNameEnum;
9 changes: 8 additions & 1 deletion packages/happy-dom/src/fetch/ResourceFetchHandler.ts
Expand Up @@ -34,7 +34,14 @@ export default class ResourceFetchHandler {
// We want to only load SyncRequest when it is needed to improve performance and not have direct dependencies to server side packages.
const absoluteURL = RelativeURL.getAbsoluteURL(document.defaultView.location, url);
const syncRequest = require('sync-request');
const response = syncRequest('GET', absoluteURL);
const response = syncRequest('GET', absoluteURL, {
headers: {
'user-agent': document.defaultView.navigator.userAgent,
cookie: document.defaultView.document.cookie,
referer: document.defaultView.location.href,
pragma: 'no-cache'
Mas0nShi marked this conversation as resolved.
Show resolved Hide resolved
}
});

if (response.isError()) {
throw new DOMException(
Expand Down
20 changes: 18 additions & 2 deletions packages/happy-dom/src/location/RelativeURL.ts
Expand Up @@ -11,16 +11,32 @@ export default class RelativeURL {
* @param url URL.
*/
public static getAbsoluteURL(location: Location, url: string): string {
// If the URL starts with '//' then it is a Protocol relative URL.
// Reference: https://url.spec.whatwg.org/#protocol-relative-urls.
// E.g. '//example.com/' needs to be converted to 'http://example.com/'.
if (url.startsWith('//')) {
return location.protocol + url;
}
// If the URL starts with '/' then it is a Path relative URL.
// E.g. '/example.com/' needs to be converted to 'http://example.com/'.
if (url.startsWith('/')) {
return location.origin + url;
}

// If the URL starts with 'https://' or 'http://' then it is a Absolute URL.
// E.g. 'https://example.com' needs to be converted to 'https://example.com/'.
// E.g. 'http://example.com' needs to be converted to 'http://example.com/'.
if (!url.startsWith('https://') && !url.startsWith('http://')) {
let pathname = location.pathname;
if (pathname.endsWith('/')) {
pathname = pathname.slice(0, -1);
}
return location.origin + pathname + '/' + url;

return (
location.origin +
(/(.*)\/.*/.test(pathname) ? pathname.match(/(.*)\/.*/)[1] : '') +
'/' +
url
);
}

return url;
Expand Down
9 changes: 9 additions & 0 deletions packages/happy-dom/src/window/Window.ts
Expand Up @@ -93,6 +93,9 @@ import * as PerfHooks from 'perf_hooks';
import VM from 'vm';
import { Buffer } from 'buffer';
import { atob, btoa } from './WindowBase64';
import XMLHttpRequest from '../xml-http-request/XMLHttpRequest';
import XMLHttpRequestUpload from '../xml-http-request/XMLHttpRequestUpload';
import { XMLHttpRequestEventTarget } from '../xml-http-request/XMLHttpRequestEventTarget';

/**
* Browser window.
Expand Down Expand Up @@ -196,6 +199,11 @@ export default class Window extends EventTarget implements IWindow {
} = Response;
public readonly DOMRect: typeof DOMRect;

// XMLHttpRequest
public XMLHttpRequest = XMLHttpRequest;
public XMLHttpRequestUpload = XMLHttpRequestUpload;
public XMLHttpRequestEventTarget = XMLHttpRequestEventTarget;

// Events
public onload: (event: Event) => void = null;
public onerror: (event: ErrorEvent) => void = null;
Expand Down Expand Up @@ -305,6 +313,7 @@ export default class Window extends EventTarget implements IWindow {
this.dispatchEvent(new Event('load'));
});

XMLHttpRequest._defaultView = this;
DOMParser._ownerDocument = this.document;
FileReader._ownerDocument = this.document;
Image.ownerDocument = this.document;
Expand Down