MCPcopy
hub / github.com/witheve/Eve / sendRequest

Method sendRequest

src/runtime/databases/http.ts:12–52  ·  view source on GitHub ↗
(evaluation, requestId, request)

Source from the content-addressed store, hash-verified

10export class HttpDatabase extends Database {
11
12 sendRequest(evaluation, requestId, request) {
13 var oReq = new XMLHttpRequest();
14 oReq.addEventListener("load", () => {
15 let body = oReq.responseText;
16 let scope = "http";
17 let responseId = `${requestId}|response`;
18 let changes = evaluation.createChanges();
19 changes.store(scope, requestId, "response", responseId, this.id);
20 changes.store(scope, responseId, "tag", "response", this.id);
21 changes.store(scope, responseId, "body", body, this.id);
22 let contentType = oReq.getResponseHeader("content-type");
23 if(contentType && contentType.indexOf("application/json") > -1 && body) {
24 let id = eavs.fromJS(changes, JSON.parse(body), this.id, scope, `${responseId}|json`);
25 changes.store(scope, responseId, "json", id, this.id);
26 }
27 evaluation.executeActions([], changes);
28 });
29 let method = "GET";
30 if(request.method) {
31 method = request.method[0];
32 }
33
34 oReq.open(method, request.url[0]);
35
36 if(request.headers) {
37 let headers = this.index.asObject(request.headers[0]);
38 for(let header in headers) {
39 oReq.setRequestHeader(header, headers[header][0]);
40 }
41 }
42
43 if(request.body) {
44 oReq.send(request.body[0]);
45 } else if(request.json) {
46 let object = this.index.asObject(request.json[0], true, true);
47 oReq.setRequestHeader("Content-Type", "application/json");
48 oReq.send(JSON.stringify(object));
49 } else {
50 oReq.send();
51 }
52 }
53
54 onFixpoint(evaluation: Evaluation, changes: Changes) {
55 let name = evaluation.databaseToName(this);

Callers 1

onFixpointMethod · 0.95

Calls 5

createChangesMethod · 0.80
executeActionsMethod · 0.80
sendMethod · 0.65
storeMethod · 0.45
asObjectMethod · 0.45

Tested by

no test coverage detected