[lib.client.xhr] now @http_token is send by the request itself
This commit is contained in:
parent
0a0fd9a27f
commit
c5e6b49fa6
|
@ -26,7 +26,6 @@ export default class XHRClientDriver extends ClientDriver{
|
||||||
|
|
||||||
/* (1) Create useful attributes */
|
/* (1) Create useful attributes */
|
||||||
this.xhr = null;
|
this.xhr = null;
|
||||||
this.http_token = null;
|
|
||||||
|
|
||||||
/* (2) Manage _resource format (remove http://, https://) */
|
/* (2) Manage _resource format (remove http://, https://) */
|
||||||
this.resource = _resource.replace(/^https?:\/\//, '');
|
this.resource = _resource.replace(/^https?:\/\//, '');
|
||||||
|
@ -110,6 +109,12 @@ export default class XHRClientDriver extends ClientDriver{
|
||||||
return false;
|
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
|
/* (2) Manage _request.path argument
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Error: invalid path format */
|
/* (1) Error: invalid path format */
|
||||||
|
@ -144,14 +149,14 @@ export default class XHRClientDriver extends ClientDriver{
|
||||||
|
|
||||||
/* (4) Open connection
|
/* (4) Open connection
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Build full URL */
|
/* (1) Build full request URI */
|
||||||
let request_url = this.resource.split(/\/$/).concat(http_uri.split(/^\//)).filter((v) => v.trim().length).join('/');
|
let request_uri = this.resource.split(/\/$/).concat(http_uri.split(/^\//)).filter((v) => v.trim().length).join('/');
|
||||||
|
|
||||||
/* (2) Build protocol (http, https) */
|
/* (2) Build protocol (http, https) and http_token */
|
||||||
let protocol = this.http_token != null ? `${this.proto}${this.http_token}@` : this.proto;
|
let protocol = http_token != null ? `${this.proto}${http_token}@` : this.proto;
|
||||||
|
|
||||||
/* (3) Open connection */
|
/* (3) Open connection */
|
||||||
this.xhr.open(http_method, `${protocol}${request_url}`, true);
|
this.xhr.open(http_method, `${protocol}${request_uri}`, true);
|
||||||
|
|
||||||
/* (3) Send request */
|
/* (3) Send request */
|
||||||
this.xhr.send(form_data);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue