PythonMonkey   v1.0.1 (dev)
Loading...
Searching...
No Matches
XMLHttpRequest Class Reference
Inheritance diagram for XMLHttpRequest:
[legend]
Collaboration diagram for XMLHttpRequest:
[legend]

Public Member Functions

get _requestMetadata ()
 
get readyState ()
 
 open (method, url, async=true, username=null, password=null)
 
 setRequestHeader (name, value)
 
get withCredentials ()
 
set withCredentials (flag)
 
get upload ()
 
 send (body=null)
 
this dispatchEvent (new ProgressEvent('loadstart', { loaded:0, total:0 }))
 
 if (!this.#uploadCompleteFlag &&this.#uploadListenerFlag) this. if(this. return
 
this this request (this.#requestMethod, this.#requestURL.toString(), this.#requestHeaders, this.#requestBody ?? '', this.timeout, processRequestBodyChunkLength, processRequestEndOfBody, processResponse, processBodyChunk, processEndOfBody,()=>(this.#timedOutFlag=true),()=>(this.#response=null), this.#debug.bind(this),).catch((e)
 
 if (this.#timedOutFlag) return this. if(this. return this. else return this. }
 
 abort ()
 
get responseURL ()
 
get status ()
 
get statusText ()
 
 getResponseHeader (name)
 
 getAllResponseHeaders ()
 
 overrideMimeType (mime)
 
get responseType ()
 
set responseType (t)
 
return this get response ()
 
get responseText ()
 
get responseXML ()
 
 for (const chunk of this.#receivedBytes)
 
- Public Member Functions inherited from EventTarget
 addEventListener (type, listener)
 
 removeEventListener (type, listener)
 
 dispatchEvent (event)
 
 _hasAnyListeners ()
 
 _hasListeners (type)
 

Public Attributes

 onreadystatechange = null
 
 UNSENT = 0
 
 OPENED = 1
 
 HEADERS_RECEIVED = 2
 
 LOADING = 3
 
 DONE = 4
 
 timeout = 0
 
let requestBodyTransmitted = 0
 
let requestBodyLength = this.#requestBody ? this.#requestBody.length : 0
 
const processRequestBodyChunkLength
 
const processRequestEndOfBody
 
let responseLength = 0
 
const processResponse
 
const processBodyChunk
 
const processEndOfBody
 
 get
 
const merged = new Uint8Array(this.#receivedLength)
 
return merged
 
- Public Attributes inherited from XMLHttpRequestEventTarget
 onloadstart
 
 onprogress
 
 onabort
 
 onerror
 
 onload
 
 ontimeout
 
 onloadend
 

Static Public Attributes

static UNSENT = 0
 
static OPENED = 1
 
static HEADERS_RECEIVED = 2
 
static LOADING = 3
 
static DONE = 4
 

Detailed Description

Implement the XMLHttpRequest API (XHR for short) according to the spec.

See also
https://xhr.spec.whatwg.org/

Member Function Documentation

◆ _requestMetadata()

get XMLHttpRequest::_requestMetadata ( )

The unique connection id to identify each XHR connection when debugging Wrapper to print debug logs with connection id information

Parameters
{string}selector Allowing others to inspect the internal properties

◆ abort()

XMLHttpRequest::abort ( )

Cancels any network activity.

See also
https://xhr.spec.whatwg.org/#the-abort()-method

◆ dispatchEvent()

this XMLHttpRequest::dispatchEvent ( new   ProgressEvent 'loadstart', { loaded:0, total:0 })

◆ for()

XMLHttpRequest::for ( const chunk of this.#  receivedBytes)

◆ getAllResponseHeaders()

XMLHttpRequest::getAllResponseHeaders ( )
Returns
{string} all the response headers, separated by CRLF, as a string, or returns null if no response has been received.

◆ getResponseHeader()

XMLHttpRequest::getResponseHeader (   name)
Parameters
{string}name
Returns
{string} the text of a particular header's value

◆ if() [1/2]

XMLHttpRequest::if ( !this.#uploadCompleteFlag &&this.#  uploadListenerFlag)

◆ if() [2/2]

XMLHttpRequest::if ( this.#  timedOutFlag)
See also
https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send step 12
https://xhr.spec.whatwg.org/#handle-errors
Parameters
{Error}e
See also
https://xhr.spec.whatwg.org/#request-error-steps
Parameters
{string}event event type
{DOMException}exception

◆ open()

XMLHttpRequest::open (   method,
  url,
  async = true,
  username = null,
  password = null 
)

◆ overrideMimeType()

XMLHttpRequest::overrideMimeType (   mime)

Acts as if the Content-Type header value for a response is mime.
(It does not change the header.)

Parameters
{string}mime

◆ readyState()

get XMLHttpRequest::readyState ( )

Returns client's state.

◆ request()

this this XMLHttpRequest::request ( this.#  requestMethod,
this.#requestURL.  toString(),
this.#  requestHeaders,
this.#requestBody ?? ''  ,
this.  timeout,
processRequestBodyChunkLength  ,
processRequestEndOfBody  ,
processResponse  ,
processBodyChunk  ,
processEndOfBody  ,
()  ,
(this.#timedOutFlag=true)  ,
()  ,
(this.#response=null)  ,
this.#debug.  bindthis 
)

◆ response()

return this get XMLHttpRequest::response ( )
See also
https://xhr.spec.whatwg.org/#text-response
Returns
{string} Returns the response body.
See also
https://xhr.spec.whatwg.org/#the-response-attribute

◆ responseText()

get XMLHttpRequest::responseText ( )

Returns response as text.

◆ responseType() [1/2]

get XMLHttpRequest::responseType ( )

◆ responseType() [2/2]

set XMLHttpRequest::responseType (   t)

◆ responseURL()

get XMLHttpRequest::responseURL ( )
Returns
{string}

◆ responseXML()

get XMLHttpRequest::responseXML ( )

Returns the response as document.

◆ send()

XMLHttpRequest::send (   body = null)

◆ setRequestHeader()

XMLHttpRequest::setRequestHeader (   name,
  value 
)

Combines a header in author request headers.

Parameters
{string}name
{string}value

◆ status()

get XMLHttpRequest::status ( )
Returns
{number} HTTP status code

◆ statusText()

get XMLHttpRequest::statusText ( )
Returns
{string} HTTP status message

◆ upload()

get XMLHttpRequest::upload ( )

Returns the associated XMLHttpRequestUpload object.
It can be used to gather transmission information when data is transferred to a server.

◆ withCredentials() [1/2]

get XMLHttpRequest::withCredentials ( )

A boolean value that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
Setting withCredentials has no effect on same-origin requests.

See also
https://xhr.spec.whatwg.org/#the-withcredentials-attribute

◆ withCredentials() [2/2]

set XMLHttpRequest::withCredentials (   flag)

Member Data Documentation

◆ DONE [1/2]

XMLHttpRequest::DONE = 4
static

@readonly

◆ DONE [2/2]

XMLHttpRequest::DONE = 4

@readonly

◆ get

XMLHttpRequest::get
Initial value:
{
return this.#receivedBytes.reduce((sum, chunk) => sum + chunk.length, 0)

@type {Method} @type {URL} @type {{ [name: string]: string; }} @type {string | Uint8Array | null} @type {import('./XMLHttpRequest-internal').XHRResponse} @type {Uint8Array[]} @type {ResponseType} cache for converting receivedBytes to the desired response type @type {ArrayBuffer | string | Record<any, any>} Get received bytes’s total length

◆ HEADERS_RECEIVED [1/2]

XMLHttpRequest::HEADERS_RECEIVED = 2
static

@readonly

◆ HEADERS_RECEIVED [2/2]

XMLHttpRequest::HEADERS_RECEIVED = 2

@readonly

◆ LOADING [1/2]

XMLHttpRequest::LOADING = 3
static

@readonly

◆ LOADING [2/2]

XMLHttpRequest::LOADING = 3

@readonly

◆ merged [1/2]

const XMLHttpRequest::merged = new Uint8Array(this.#receivedLength)

Concatenate received bytes into one single Uint8Array

◆ merged [2/2]

return XMLHttpRequest::merged

◆ onreadystatechange

XMLHttpRequest::onreadystatechange = null

@type {EventListenerFn}

◆ OPENED [1/2]

XMLHttpRequest::OPENED = 1
static

@readonly

◆ OPENED [2/2]

XMLHttpRequest::OPENED = 1

@readonly

◆ processBodyChunk

const XMLHttpRequest::processBodyChunk
Initial value:
= ( bytes) =>
{
this.#debug('xhr:response')(`recv chunk, ${bytes.length} bytes «${trunc(bytes, 100)}»`);
this.#receivedBytes.push(bytes);
if (this.#state === XMLHttpRequest.HEADERS_RECEIVED)
this.#state = XMLHttpRequest.LOADING;
this.dispatchEvent(new Event('readystatechange'));
this.dispatchEvent(new ProgressEvent('progress', { loaded:this.#receivedLength, total:responseLength }));
}
function trunc(what, maxlen, coerce)
Definition XMLHttpRequest.js:26
const debug
Definition XMLHttpRequest.js:16
Definition event-target.js:18
Definition XMLHttpRequest.js:49
Definition XMLHttpRequest.js:102
this dispatchEvent(new ProgressEvent('loadstart', { loaded:0, total:0 }))
let responseLength
Definition XMLHttpRequest.js:371
static LOADING
Definition XMLHttpRequest.js:141
static HEADERS_RECEIVED
Definition XMLHttpRequest.js:140

◆ processEndOfBody

const XMLHttpRequest::processEndOfBody
Initial value:
= () =>
{
this.#debug('xhr:response')(`end of body, received ${this.#receivedLength} bytes`);
const transmitted = this.#receivedLength;
const length = responseLength || 0;
this.dispatchEvent(new ProgressEvent('progress', { loaded:transmitted, total:length }));
this.#state = XMLHttpRequest.DONE;
this.#sendFlag = false;
this.dispatchEvent(new Event('readystatechange'));
for (const eventType of ['load', 'loadend'])
this.dispatchEvent(new ProgressEvent(eventType, { loaded:transmitted, total:length }));
}
static DONE
Definition XMLHttpRequest.js:142
See also
https://xhr.spec.whatwg.org/#handle-response-end-of-body

◆ processRequestBodyChunkLength

const XMLHttpRequest::processRequestBodyChunkLength
Initial value:
= ( bytesLength) =>
{
requestBodyTransmitted += bytesLength;
if (this.#uploadListenerFlag)
this.#uploadObject.dispatchEvent(new ProgressEvent('progress', { loaded:requestBodyTransmitted, total:requestBodyLength }));
}
let requestBodyTransmitted
Definition XMLHttpRequest.js:344
let requestBodyLength
Definition XMLHttpRequest.js:345

◆ processRequestEndOfBody

const XMLHttpRequest::processRequestEndOfBody
Initial value:
= () =>
{
this.#uploadCompleteFlag = true;
if (!this.#uploadListenerFlag)
return;
for (const eventType of ['progress', 'load', 'loadend'])
this.#uploadObject.dispatchEvent(new ProgressEvent(eventType, { loaded:requestBodyTransmitted, total:requestBodyLength }));
}

◆ processResponse

const XMLHttpRequest::processResponse
Initial value:
= (response) =>
{
this.#debug('xhr:response')(`response headers ----\n${response.getAllResponseHeaders()}`);
this.#response = response;
this.dispatchEvent(new Event('readystatechange'));
if (this.#state !== XMLHttpRequest.HEADERS_RECEIVED)
return;
responseLength = this.#response.contentLength;
}
return this get response()
Definition XMLHttpRequest.js:612

◆ requestBodyLength

let XMLHttpRequest::requestBodyLength = this.#requestBody ? this.#requestBody.length : 0

◆ requestBodyTransmitted

let XMLHttpRequest::requestBodyTransmitted = 0

◆ responseLength

let XMLHttpRequest::responseLength = 0

◆ timeout

XMLHttpRequest::timeout = 0

Timeout time in milliseconds.
When set to a non-zero value will cause fetching to terminate after the given time has passed.

◆ UNSENT [1/2]

XMLHttpRequest::UNSENT = 0
static

@readonly

◆ UNSENT [2/2]

XMLHttpRequest::UNSENT = 0

@readonly


The documentation for this class was generated from the following file: