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

Add headers to resources #2957

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/engine/Resources/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
public data: T = null;
public logger: Logger = Logger.getInstance();
public events = new EventEmitter();
/**
* Response headers are populated after load
*/
public headers = new Map<string, string>();

/**
* @param path Path to the remote resource
Expand Down Expand Up @@ -90,6 +94,25 @@
this.logger.debug('Completed loading resource', this.path);
resolve(this.data);
});
request.addEventListener('readystatechange', e => {
if (request.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
// Get the raw header string
const headers = request.getAllResponseHeaders();

Check failure on line 101 in src/engine/Resources/Resource.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
// Convert the header string into an array
// of individual headers
const arr = headers.trim().split(/[\r\n]+/);

// Create a map of header names to values
arr.forEach((line) => {
const parts = line.split(": ");

Check failure on line 108 in src/engine/Resources/Resource.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
const header = parts.shift();
const value = parts.join(": ");

Check failure on line 110 in src/engine/Resources/Resource.ts

View workflow job for this annotation

GitHub Actions / build

Strings must use singlequote
this.headers.set(header.toLowerCase(), value.toLowerCase());
});
}
});

request.send();
});
}
Expand Down
Loading