1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

[spidermonkey] Set user and password for xhr_open

This commit is contained in:
Witold Filipczyk 2022-09-21 20:38:34 +02:00
parent 2b4368aee3
commit 924b494ba6

View File

@ -354,6 +354,38 @@ xhr_open(JSContext *ctx, unsigned int argc, JS::Value *rval)
} else {
xhr->async = true;
}
char *username = NULL;
char *password = NULL;
if (argc > 3) {
username = jsval_to_string(ctx, args[3]);
}
if (argc > 4) {
password = jsval_to_string(ctx, args[4]);
}
if (!username && !password) {
args.rval().setUndefined();
return true;
}
if (username) {
xhr->uri->user = username;
xhr->uri->userlen = strlen(username);
}
if (password) {
xhr->uri->password = password;
xhr->uri->passwordlen = strlen(password);
}
char *url2 = get_uri_string(xhr->uri, URI_DIR_LOCATION | URI_PATH | URI_USER | URI_PASSWORD);
mem_free_if(username);
mem_free_if(password);
if (!url2) {
return false;
}
done_uri(xhr->uri);
xhr->uri = get_uri(url2, URI_DIR_LOCATION | URI_PATH | URI_USER | URI_PASSWORD);
mem_free(url2);
args.rval().setUndefined();
return true;