MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / XhrResponse

Class XhrResponse

utils/upload.ts:185–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183}
184
185class XhrResponse {
186 ok: boolean;
187 headers: Headers;
188 status: number;
189 statusText: string;
190 url: string;
191
192 constructor(private xhr: XMLHttpRequest) {
193 this.status = xhr.status;
194 this.statusText = xhr.statusText;
195 this.url = xhr.responseURL;
196 this.ok = this.status >= 200 && this.status < 300;
197 this.headers = new Headers();
198
199 const rawHeaders = xhr.getAllResponseHeaders();
200 for (const line of rawHeaders.trim().split(/[\r\n]+/)) {
201 if (!line) continue;
202
203 const separatorIndex = line.indexOf(":");
204 if (separatorIndex < 0) continue;
205
206 this.headers.append(line.slice(0, separatorIndex).trim(), line.slice(separatorIndex + 1).trim());
207 }
208 }
209
210 async text(): Promise<string> {
211 return typeof this.xhr.response === "string"
212 ? this.xhr.response
213 : this.xhr.responseText;
214 }
215
216 async json(): Promise<unknown> {
217 return JSON.parse(await this.text());
218 }
219}
220
221function setXhrUploadProgress(event: ProgressEvent) {
222 if (!event.lengthComputable || event.total <= 0) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected