[lib.client.xhr] now @http_token is send by the request itself

This commit is contained in:
xdrm-brackets 2018-03-25 13:55:31 +02:00
parent 0a0fd9a27f
commit c5e6b49fa6
1 changed files with 11 additions and 21 deletions

View File

@ -26,7 +26,6 @@ export default class XHRClientDriver extends ClientDriver{
/* (1) Create useful attributes */
this.xhr = null;
this.http_token = null;
/* (2) Manage _resource format (remove http://, https://) */
this.resource = _resource.replace(/^https?:\/\//, '');
@ -110,6 +109,12 @@ export default class XHRClientDriver extends ClientDriver{
return false;
}
/* (3) Default @http_token value */
let http_token = null;
if( typeof _request.http_token === 'string' )
http_token = _request.http_token;
/* (2) Manage _request.path argument
---------------------------------------------------------*/
/* (1) Error: invalid path format */
@ -144,14 +149,14 @@ export default class XHRClientDriver extends ClientDriver{
/* (4) Open connection
---------------------------------------------------------*/
/* (1) Build full URL */
let request_url = this.resource.split(/\/$/).concat(http_uri.split(/^\//)).filter((v) => v.trim().length).join('/');
/* (1) Build full request URI */
let request_uri = this.resource.split(/\/$/).concat(http_uri.split(/^\//)).filter((v) => v.trim().length).join('/');
/* (2) Build protocol (http, https) */
let protocol = this.http_token != null ? `${this.proto}${this.http_token}@` : this.proto;
/* (2) Build protocol (http, https) and http_token */
let protocol = http_token != null ? `${this.proto}${http_token}@` : this.proto;
/* (3) Open connection */
this.xhr.open(http_method, `${protocol}${request_url}`, true);
this.xhr.open(http_method, `${protocol}${request_uri}`, true);
/* (3) Send request */
this.xhr.send(form_data);
@ -161,19 +166,4 @@ export default class XHRClientDriver extends ClientDriver{
}
/* (4) Set HTTP token
*
* @_token<String> HTTP token
*
---------------------------------------------------------*/
setHttpToken(_token=null){
/* Manage _token default values */
if( typeof _token === 'string' )
this.http_token = _token;
else
this.http_token = null;
}
}