Skip to content

Commit b463778

Browse files
committed
feat(XHR): implement xhr.withCredentials getter/setter
1 parent 320462f commit b463778

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

python/pythonmonkey/builtin_modules/XMLHttpRequest.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,27 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
176176
*/
177177
timeout = 0;
178178

179+
/**
180+
* 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.
181+
* Setting withCredentials has no effect on same-origin requests.
182+
* @see https://xhr.spec.whatwg.org/#the-withcredentials-attribute
183+
*/
179184
get withCredentials()
180185
{
181-
return false;
186+
return this.#crossOriginCredentials;
182187
}
183188
set withCredentials(flag)
184189
{
185-
// do nothing
190+
// step 1
191+
if (this.#state !== XMLHttpRequest.UNSENT && this.#state !== XMLHttpRequest.OPENED)
192+
// The XHR internal state should be UNSENT or OPENED.
193+
throw new DOMException('XMLHttpRequest must not be sending.', 'InvalidStateError');
194+
// step 2
195+
if (this.#sendFlag)
196+
throw new DOMException('send() has already been called', 'InvalidStateError');
197+
// step 3
198+
this.#crossOriginCredentials = flag;
199+
// TODO: figure out what cross-origin means in PythonMonkey. Is it always same-origin request? What to send?
186200
}
187201

188202
/**
@@ -565,6 +579,7 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget
565579
#uploadObject = new XMLHttpRequestUpload();
566580
#state = XMLHttpRequest.UNSENT; // One of unsent, opened, headers received, loading, and done; initially unsent.
567581
#sendFlag = false; // A flag, initially unset.
582+
#crossOriginCredentials = false; // A boolean, initially false.
568583
/** @type {Method} */
569584
#requestMethod = null;
570585
/** @type {URL} */

0 commit comments

Comments
 (0)