forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtst.js
More file actions
353 lines (261 loc) · 7.81 KB
/
tst.js
File metadata and controls
353 lines (261 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import request from 'request';
import requestPromise from 'request-promise';
import superagent from 'superagent';
import http from 'http';
import express from 'express';
import axios from 'axios';
import got from 'got';
import nodeFetch from 'node-fetch';
import {ClientRequest, net} from 'electron';
(function() {
request(url);
request.get(url);
request.delete(url);
request({ url: url });
requestPromise(url);
superagent.get(url);
http.get(url);
axios(url);
axios.get(url);
axios({ url: url });
got(url);
got.stream(url);
window.fetch(url);
nodeFetch(url);
net.request(url);
net.request({ url: url });
new ClientRequest(url);
new ClientRequest({ url: url });
unknown(url);
unknown({ url:url });
});
(function() {
axios({data: data});
axios.get(x, {data: not_data});
axios.post(x, data1, {data: data2});
axios({headers: headerData, params: paramsData});
window.fetch(url, {headers: headerData, body: bodyData});
got(url, {headers: headerData, body: bodyData, quer: queryData});
superagent.get(url).query(data);
superagent.get(url).set('x', headerData)
superagent.post(url).send(bodyData);
superagent.get(url).set('x', headerData).query(queryData);
superagent.get(url).unknown(nonData).query(queryData);
});
(function() {
$.ajax(url, {data: data});
$.ajax({url: url, tdata: data});
$.getJSON(url, {data: data}); // the entire "{data: data}" object is the data.
$.getJSON({url: url, tdata: data}); // not how to use getJSON.
var xhr = new XMLHttpRequest();
xhr.open(_, url);
xhr.send(data);
});
(function() {
http.get(relativeUrl, {host: host});
axios({host: host});
got(relativeUrl, {host: host});
net.request({ hostname: host });
});
(function() {
var xhr = new XMLHttpRequest();
xhr.responseType = "json";
xhr.open(_, url);
xhr.send(data);
xhr.onreadystatechange = function() {
this.response;
};
var xhr2 = new XMLHttpRequest();
xhr2.open(_, url);
xhr2.send(data);
xhr2.addEventListener("readystatechange", function() {
this.responseText;
this.responseXML;
this.statusText;
});
})
(function() {
request(url, function (error, response, body) {
error;
response.body;
body;
});
request(url, {json: true}, function (error, response, body) {
error;
response.body;
body;
});
requestPromise(url, {json: true});
});
(function() {
axios.get(url).then(response => response.data);
axios({ url: url, responseType: 'json'}).then(response => response.data);
axios(unknown).then(response => response.data);
axios({ responseType: unknown }).then(response => response.data);
})
(function() {
fetch(url).then(r => r.json()).then(json => json);
})
(function() {
got(url).then(response => response.body);
got(url, { json: true }).then(response => response.body);
got.stream(url).pipe(process.stdout);
})
(function() {
superagent.get(url).end((err, res) => {
err;
res;
});
});
(function() {
let XhrIo = goog.require('goog.net.XhrIo');
let xhr = new XhrIo();
xhr.send(url);
xhr.addEventListener('readystatechange', function() {
xhr.getResponseJson();
xhr.getResponseHeaders();
});
})
(function() {
let base = request;
let variant1 = base.defaults({});
let variant2 = variant1.defaults({});
base(url);
variant1(url);
variant2(url);
});
(function() {
$.get( "ajax/test.html", function( data ) {});
$.getJSON( "ajax/test.json", "MyData", function( data ) {});
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {});
$.post( "ajax/test.html", "PostData", function( data ) { });
$( "#result" ).load( "ajax/test.html", function(result) {});
$.ajax({
type: "POST",
url: "http://example.org",
data: "AjaxData",
success: (ajaxData) => {},
dataType: "json"
});
$.get( "ajax/test.json", function( data ) {}, "json");
$.ajax({url: "ajax/blob", dataType: "blob"})
.done(function( data ) {});
$.get("example.php").done(function(response) {})
$.ajax({
url: "example.php",
type: 'POST',
dataType: "json",
error: function (err) {
console.log(err.responseText)
}});
$.get("example.php").fail(function(xhr) {console.log(xhr.responseText)});
});
const net = require("net");
(function () {
var data = {
socket: new net.Socket()
}
data.socket.connect({host: "myHost"});
data.socket.on("data", (data) => {});
data.socket.write("foobar");
})();
const needle = require("needle");
(function () {
const options = { headers: { 'X-Custom-Header': 'Bumbaway atuna' } };
needle("POST", "http://example.org/foo/bar", "MyData", options).then(function(resp) { console.log(resp.body) });
needle.get("http://example.org", (err, resp, body) => {
});
needle.post("http://example.org/post", "data", options, (err, resp, body) => {
});
})();
var FormData = require('form-data');
var request = require('request');
var form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', Buffer.from("foo"));
form.append('my_logo', request('http://example.org/images/logo.png'));
form.submit('http://example.org/', (err, res) => {
res.resume();
});
var form = new FormData();
form.append('new_form', 'new_value');
form.submit({
method: 'post',
host: 'example.org',
path: '/upload',
headers: form.getHeaders()
});
var httpProxy = require('http-proxy');
var http = require("http");
httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
var proxy = httpProxy.createProxyServer(options);
http.createServer(function(req, res) {
proxy.web(req, res, { target: 'http://mytarget.com:8080' });
});
httpProxy.createProxyServer({
target: {
protocol: 'https:',
host: 'my-domain-name',
port: 443,
pfx: fs.readFileSync('path/to/certificate.p12'),
passphrase: 'password',
},
changeOrigin: true
}).listen(8000);
function webSocket() {
const socket = new WebSocket('ws://localhost:8080');
socket.addEventListener('open', function (event) {
socket.send('Hello Server!');
});
socket.addEventListener('message', function (event) {
console.log("Data from server: " + event.data);
});
}
function moreAxios() {
axios({
method: 'GET',
url: "http://example.org/more-axios",
}).then(
x => res.send(x.data),
(err) => {
const status = err.response.status;
const data = err.response.data;
const agent = err.response.headers.useragent;
}
);
}
import { fetch as fetchPolyfill } from 'whatwg-fetch'
function usePolyfill() {
return fetchPolyfill('/foo/bar')
.then(function (response) {
return response.text()
})
}
function useSuperagent(url){
superagent('GET', url);
superagent.del(url);
superagent.agent().post(url).send(data);
}
import { Options } from 'got';
function gotTests(url){
const options = new Options({url});
got(undefined, undefined, options);
got(undefined, undefined, new Options({url}));
const options2 = new Options({url});
got.extend(options2).extend(options).get();
got.paginate(url, {});
const jsonClient = got.extend({url: url});
jsonClient.get();
const jsonClient2 = got.extend({url: url}).extend({url: url});
jsonClient2.get();
}
function moreAxiosTests(url, data, config){
axios.postForm(url, data, config);
axios.putForm(url, data);
axios.putForm(url, data, config);
axios.patchForm(url, data);
axios.patchForm(url, data, config);
axios.getUri({ url: url });
const axiosInstance = axios.create({});
axiosInstance({method: "get", url: url, responseType: "text"});
}