746201ed49
Adds xhr connection managment to http/1.1 installs This includes various things: 1. An object pool to 'acquire', 'release' and 'dispose' of objects, also a 'purge' to completely empty it 2. A `Request` data object, mainly for reasoning about the object better 3. A pseudo http 'client' which doens't actually control the request itself but does help to manage the connections An initializer is used to detect the script element of the consul-ui sourcecode which we use later to sniff the protocol that we are most likely using for API access
30 lines
700 B
JavaScript
30 lines
700 B
JavaScript
export default class {
|
|
constructor(method, url, headers, xhr) {
|
|
this._xhr = xhr;
|
|
this._url = url;
|
|
this._method = method;
|
|
this._headers = headers;
|
|
this._headers = {
|
|
...headers,
|
|
'content-type': 'application/json',
|
|
'x-request-id': `${this._method} ${this._url}?${JSON.stringify(headers.body)}`,
|
|
};
|
|
if (typeof this._headers.body.index !== 'undefined') {
|
|
// this should probably be in a response
|
|
this._headers['content-type'] = 'text/event-stream';
|
|
}
|
|
}
|
|
headers() {
|
|
return this._headers;
|
|
}
|
|
getId() {
|
|
return this._headers['x-request-id'];
|
|
}
|
|
abort() {
|
|
this._xhr.abort();
|
|
}
|
|
connection() {
|
|
return this._xhr;
|
|
}
|
|
}
|