reqrio 0.2.0-beta2 → 0.3.0-alpha4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -110
- package/Response.js +52 -52
- package/bindings.js +79 -82
- package/libreqrio.so +0 -0
- package/package.json +26 -26
- package/reqrio.dll +0 -0
- package/session.js +182 -180
- package/test.js +15 -17
- package/ws.js +58 -58
- package/2.log +0 -47
package/README.md
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
### reqrio is an HTTP request library designed for fast, simple, and convenient HTTP request usage.
|
|
2
|
-
|
|
3
|
-
* Features: Low copy, high concurrency, low overhead
|
|
4
|
-
|
|
5
|
-
* Supports TLS fingerprinting, which can be configured via hexadecimal, Ja3, or Ja4 TLS handshake settings (*
|
|
6
|
-
*subscription only**).
|
|
7
|
-
|
|
8
|
-
* Ensures **request header order** (see [Request Header Order Table](#request-header-order-table)), consistent with
|
|
9
|
-
browsers.
|
|
10
|
-
|
|
11
|
-
* Uses **BoringSSL** to implement TLS, consistent with browsers like Chrome and Edge.
|
|
12
|
-
### Low-Copy
|
|
13
|
-
|
|
14
|
-
`reqrio` is a low copy request sending engine used to efficiently encrypt user or file data over TLS and send it to TCP. `reqrio`
|
|
15
|
-
Convert user input data such as form data, json, bytes, text, etc. into bytes for storage, and only copy once during TLS encryption, while only the data is processed in other stages
|
|
16
|
-
Borrow (borrowing). File uploads are read through into_deader to reduce memory overhead
|
|
17
|
-
|
|
18
|
-
```text
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
User
|
|
22
|
-
|
|
23
|
-
│ AcReq │ │ borrow
|
|
24
|
-
Files │(Engine)│ into_reader │
|
|
25
|
-
User
|
|
26
|
-
└────────┘ └──────────┘ └──────────┘
|
|
27
|
-
```
|
|
28
|
-
### Request Header Order Table
|
|
29
|
-
|
|
30
|
-
| No. | HTTP/2.0 | HTTP/1.1 |
|
|
31
|
-
|:----|:----------------------------|:--------------------------|
|
|
32
|
-
| 1 | cache-control | Host |
|
|
33
|
-
| 2 | sec-ch-ua | Connection |
|
|
34
|
-
| 3 | sec-ch-ua-mobile | Content-Length |
|
|
35
|
-
| 4 | sec-ch-ua-full-version | Authorization |
|
|
36
|
-
| 5 | sec-ch-ua-arch | Content-Type |
|
|
37
|
-
| 6 | sec-ch-ua-platform | Cache-Control |
|
|
38
|
-
| 7 | sec-ch-ua-platform-version | sec-ch-ua |
|
|
39
|
-
| 8 | sec-ch-ua-model | sec-ch-ua-mobile |
|
|
40
|
-
| 9 | sec-ch-ua-bitness | sec-ch-ua-platform |
|
|
41
|
-
| 10 | sec-ch-ua-full-version-list | Upgrade-Insecure-Requests |
|
|
42
|
-
| 11 | upgrade-insecure-requests | User-Agent |
|
|
43
|
-
| 12 | user-agent | Accept |
|
|
44
|
-
| 13 | accept | Sec-Fetch-Site |
|
|
45
|
-
| 14 | origin | Sec-Fetch-Mode |
|
|
46
|
-
| 15 | sec-fetch-site | Sec-Fetch-User |
|
|
47
|
-
| 16 | sec-fetch-mode | Sec-Fetch-Dest |
|
|
48
|
-
| 17 | sec-fetch-user | Sec-Fetch-Storage-Access |
|
|
49
|
-
| 18 | sec-fetch-dest | Referer |
|
|
50
|
-
| 19 | sec-fetch-storage-access | Accept-Encoding |
|
|
51
|
-
| 20 | referer | Accept-Language |
|
|
52
|
-
| 21 | accept-encoding | Cookie |
|
|
53
|
-
| 22 | accept-language | Origin |
|
|
54
|
-
| 23 | cookie | |
|
|
55
|
-
| 24 | priority | |
|
|
56
|
-
| | //unknown | |
|
|
57
|
-
| 25 | content-encoding | |
|
|
58
|
-
| 26 | content-type | |
|
|
59
|
-
| 27 | authorization | |
|
|
60
|
-
| 28 | content-type | |
|
|
61
|
-
|
|
62
|
-
### Usage examples:
|
|
63
|
-
|
|
64
|
-
* Http Example
|
|
65
|
-
|
|
66
|
-
```js
|
|
67
|
-
const {Session, ALPN} = require("reqrio")
|
|
68
|
-
|
|
69
|
-
let session = new Session(ALPN.HTTP11)
|
|
70
|
-
session.set_headers({
|
|
71
|
-
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
72
|
-
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
73
|
-
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
|
|
74
|
-
"Cache-Control": "no-cache",
|
|
75
|
-
"Connection": "keep-alive",
|
|
76
|
-
"Cookie": "__guid=15015764.1071255116101212729.1764940193317.2156; env_webp=1; _S=pvc5q7leemba50e4kn4qis4b95; QiHooGUID=4C8051464B2D97668E3B21198B9CA207.1766289287750; count=1; so-like-red=2; webp=1; so_huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; __huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; gtHuid=1",
|
|
77
|
-
"Host": "m.so.com",
|
|
78
|
-
"Pragma": "no-cache",
|
|
79
|
-
"Sec-Fetch-Dest": "document",
|
|
80
|
-
"Sec-Fetch-Mode": "navigate",
|
|
81
|
-
"Sec-Fetch-Site": "none",
|
|
82
|
-
"Sec-Fetch-User": "?1",
|
|
83
|
-
"Upgrade-Insecure-Requests": 1,
|
|
84
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0",
|
|
85
|
-
"sec-ch-ua": '"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
|
86
|
-
"sec-ch-ua-mobile": "?0",
|
|
87
|
-
"sec-ch-ua-platform": '"Windows"'
|
|
88
|
-
})
|
|
89
|
-
session.set_url('https://m.so.com')
|
|
90
|
-
let resp = session.get()
|
|
91
|
-
console.log(resp.status_code())
|
|
92
|
-
session.close()
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
* WebSocket Example
|
|
97
|
-
|
|
98
|
-
```js
|
|
99
|
-
const {Websocket} = require('index')
|
|
100
|
-
|
|
101
|
-
let ws = new Websocket();
|
|
102
|
-
ws.set_url("wss://api.github.com")
|
|
103
|
-
ws.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0")
|
|
104
|
-
ws.set_proxy("http://127.0.0.1:7878")
|
|
105
|
-
ws.open()
|
|
106
|
-
while (true) {
|
|
107
|
-
frame = ws.read()
|
|
108
|
-
console.log(frame)
|
|
109
|
-
}
|
|
110
|
-
|
|
1
|
+
### reqrio is an HTTP request library designed for fast, simple, and convenient HTTP request usage.
|
|
2
|
+
|
|
3
|
+
* Features: Low copy, high concurrency, low overhead
|
|
4
|
+
|
|
5
|
+
* Supports TLS fingerprinting, which can be configured via hexadecimal, Ja3, or Ja4 TLS handshake settings (*
|
|
6
|
+
*subscription only**).
|
|
7
|
+
|
|
8
|
+
* Ensures **request header order** (see [Request Header Order Table](#request-header-order-table)), consistent with
|
|
9
|
+
browsers.
|
|
10
|
+
|
|
11
|
+
* Uses **BoringSSL** to implement TLS, consistent with browsers like Chrome and Edge.
|
|
12
|
+
### Low-Copy
|
|
13
|
+
|
|
14
|
+
`reqrio` is a low copy request sending engine used to efficiently encrypt user or file data over TLS and send it to TCP. `reqrio`
|
|
15
|
+
Convert user input data such as form data, json, bytes, text, etc. into bytes for storage, and only copy once during TLS encryption, while only the data is processed in other stages
|
|
16
|
+
Borrow (borrowing). File uploads are read through into_deader to reduce memory overhead
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
|
|
20
|
+
Form ┌────────┐encode->bytes ┌──────────┐ ┌──────────┐
|
|
21
|
+
User ───────►│ │─────────────►│ │ │ │
|
|
22
|
+
Json │ ScReq │ into_bytes │ Request │ copy slice │ fragment │ write ┌───────┐
|
|
23
|
+
│ AcReq │ │ borrow │────────────►│ TLS │──────►│ TCP │
|
|
24
|
+
Files │(Engine)│ into_reader │ reader │ │ Encrypt │ └───────┘
|
|
25
|
+
User ───────►│ │─────────────►│ │ │ │
|
|
26
|
+
└────────┘ └──────────┘ └──────────┘
|
|
27
|
+
```
|
|
28
|
+
### Request Header Order Table
|
|
29
|
+
|
|
30
|
+
| No. | HTTP/2.0 | HTTP/1.1 |
|
|
31
|
+
|:----|:----------------------------|:--------------------------|
|
|
32
|
+
| 1 | cache-control | Host |
|
|
33
|
+
| 2 | sec-ch-ua | Connection |
|
|
34
|
+
| 3 | sec-ch-ua-mobile | Content-Length |
|
|
35
|
+
| 4 | sec-ch-ua-full-version | Authorization |
|
|
36
|
+
| 5 | sec-ch-ua-arch | Content-Type |
|
|
37
|
+
| 6 | sec-ch-ua-platform | Cache-Control |
|
|
38
|
+
| 7 | sec-ch-ua-platform-version | sec-ch-ua |
|
|
39
|
+
| 8 | sec-ch-ua-model | sec-ch-ua-mobile |
|
|
40
|
+
| 9 | sec-ch-ua-bitness | sec-ch-ua-platform |
|
|
41
|
+
| 10 | sec-ch-ua-full-version-list | Upgrade-Insecure-Requests |
|
|
42
|
+
| 11 | upgrade-insecure-requests | User-Agent |
|
|
43
|
+
| 12 | user-agent | Accept |
|
|
44
|
+
| 13 | accept | Sec-Fetch-Site |
|
|
45
|
+
| 14 | origin | Sec-Fetch-Mode |
|
|
46
|
+
| 15 | sec-fetch-site | Sec-Fetch-User |
|
|
47
|
+
| 16 | sec-fetch-mode | Sec-Fetch-Dest |
|
|
48
|
+
| 17 | sec-fetch-user | Sec-Fetch-Storage-Access |
|
|
49
|
+
| 18 | sec-fetch-dest | Referer |
|
|
50
|
+
| 19 | sec-fetch-storage-access | Accept-Encoding |
|
|
51
|
+
| 20 | referer | Accept-Language |
|
|
52
|
+
| 21 | accept-encoding | Cookie |
|
|
53
|
+
| 22 | accept-language | Origin |
|
|
54
|
+
| 23 | cookie | |
|
|
55
|
+
| 24 | priority | |
|
|
56
|
+
| | //unknown | |
|
|
57
|
+
| 25 | content-encoding | |
|
|
58
|
+
| 26 | content-type | |
|
|
59
|
+
| 27 | authorization | |
|
|
60
|
+
| 28 | content-type | |
|
|
61
|
+
|
|
62
|
+
### Usage examples:
|
|
63
|
+
|
|
64
|
+
* Http Example
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
const {Session, ALPN} = require("reqrio")
|
|
68
|
+
|
|
69
|
+
let session = new Session(ALPN.HTTP11)
|
|
70
|
+
session.set_headers({
|
|
71
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
72
|
+
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
73
|
+
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
|
|
74
|
+
"Cache-Control": "no-cache",
|
|
75
|
+
"Connection": "keep-alive",
|
|
76
|
+
"Cookie": "__guid=15015764.1071255116101212729.1764940193317.2156; env_webp=1; _S=pvc5q7leemba50e4kn4qis4b95; QiHooGUID=4C8051464B2D97668E3B21198B9CA207.1766289287750; count=1; so-like-red=2; webp=1; so_huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; __huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; gtHuid=1",
|
|
77
|
+
"Host": "m.so.com",
|
|
78
|
+
"Pragma": "no-cache",
|
|
79
|
+
"Sec-Fetch-Dest": "document",
|
|
80
|
+
"Sec-Fetch-Mode": "navigate",
|
|
81
|
+
"Sec-Fetch-Site": "none",
|
|
82
|
+
"Sec-Fetch-User": "?1",
|
|
83
|
+
"Upgrade-Insecure-Requests": 1,
|
|
84
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0",
|
|
85
|
+
"sec-ch-ua": '"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
|
86
|
+
"sec-ch-ua-mobile": "?0",
|
|
87
|
+
"sec-ch-ua-platform": '"Windows"'
|
|
88
|
+
})
|
|
89
|
+
session.set_url('https://m.so.com')
|
|
90
|
+
let resp = session.get()
|
|
91
|
+
console.log(resp.status_code())
|
|
92
|
+
session.close()
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
* WebSocket Example
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
const {Websocket} = require('index')
|
|
100
|
+
|
|
101
|
+
let ws = new Websocket();
|
|
102
|
+
ws.set_url("wss://api.github.com")
|
|
103
|
+
ws.add_header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0")
|
|
104
|
+
ws.set_proxy("http://127.0.0.1:7878")
|
|
105
|
+
ws.open()
|
|
106
|
+
while (true) {
|
|
107
|
+
frame = ws.read()
|
|
108
|
+
console.log(frame)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
111
|
```
|
package/Response.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
class Header {
|
|
2
|
-
constructor(json) {
|
|
3
|
-
if (!json) return
|
|
4
|
-
this.uri = json.uri;
|
|
5
|
-
this.method = json.method;
|
|
6
|
-
this.status = json.status;
|
|
7
|
-
this.agreement = json.agreement;
|
|
8
|
-
this.keys = json.keys
|
|
9
|
-
this.cookies = []
|
|
10
|
-
|
|
11
|
-
if (this.keys["Set-Cookie"]) {
|
|
12
|
-
for (let i = 0; i < this.keys["Set-Cookie"].length; i++) {
|
|
13
|
-
this.cookies.push(this.keys["Set-Cookie"][i])
|
|
14
|
-
}
|
|
15
|
-
delete this.keys["Set-Cookie"]
|
|
16
|
-
}
|
|
17
|
-
if (this.keys["set-cookie"]) {
|
|
18
|
-
for (let i = 0; i < this.keys["set-cookie"].length; i++) {
|
|
19
|
-
this.cookies.push(this.keys["set-cookie"][i])
|
|
20
|
-
}
|
|
21
|
-
delete this.keys["set-cookie"]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class Response {
|
|
30
|
-
constructor(bytes) {
|
|
31
|
-
let resp_text = bytes.toString('utf8')
|
|
32
|
-
try {
|
|
33
|
-
let resp_json = JSON.parse(resp_text);
|
|
34
|
-
this.header = new Header(resp_json.header);
|
|
35
|
-
this.body = Buffer.from(resp_json.body, 'hex')
|
|
36
|
-
} catch (e) {
|
|
37
|
-
throw resp_text
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
status_code() {
|
|
42
|
-
return this.header.status
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
text() {
|
|
46
|
-
return this.body.toString('utf8')
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
Response, Header
|
|
1
|
+
class Header {
|
|
2
|
+
constructor(json) {
|
|
3
|
+
if (!json) return
|
|
4
|
+
this.uri = json.uri;
|
|
5
|
+
this.method = json.method;
|
|
6
|
+
this.status = json.status;
|
|
7
|
+
this.agreement = json.agreement;
|
|
8
|
+
this.keys = json.keys
|
|
9
|
+
this.cookies = []
|
|
10
|
+
|
|
11
|
+
if (this.keys["Set-Cookie"]) {
|
|
12
|
+
for (let i = 0; i < this.keys["Set-Cookie"].length; i++) {
|
|
13
|
+
this.cookies.push(this.keys["Set-Cookie"][i])
|
|
14
|
+
}
|
|
15
|
+
delete this.keys["Set-Cookie"]
|
|
16
|
+
}
|
|
17
|
+
if (this.keys["set-cookie"]) {
|
|
18
|
+
for (let i = 0; i < this.keys["set-cookie"].length; i++) {
|
|
19
|
+
this.cookies.push(this.keys["set-cookie"][i])
|
|
20
|
+
}
|
|
21
|
+
delete this.keys["set-cookie"]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Response {
|
|
30
|
+
constructor(bytes) {
|
|
31
|
+
let resp_text = bytes.toString('utf8')
|
|
32
|
+
try {
|
|
33
|
+
let resp_json = JSON.parse(resp_text);
|
|
34
|
+
this.header = new Header(resp_json.header);
|
|
35
|
+
this.body = Buffer.from(resp_json.body, 'hex')
|
|
36
|
+
} catch (e) {
|
|
37
|
+
throw resp_text
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
status_code() {
|
|
42
|
+
return this.header.status
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
text() {
|
|
46
|
+
return this.body.toString('utf8')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
Response, Header
|
|
53
53
|
}
|
package/bindings.js
CHANGED
|
@@ -1,82 +1,79 @@
|
|
|
1
|
-
const ffi = require('ffi-napi');
|
|
2
|
-
const ref = require('ref-napi');
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
const voidPtr = ref.refType(ref.types.void);
|
|
6
|
-
const charPtr = ref.types.CString;
|
|
7
|
-
const uint8Ptr = ref.refType(ref.types.uint8);
|
|
8
|
-
|
|
9
|
-
const Method = {
|
|
10
|
-
GET: 0,
|
|
11
|
-
POST: 1,
|
|
12
|
-
PUT: 2,
|
|
13
|
-
HEAD: 3,
|
|
14
|
-
DELETE: 4,
|
|
15
|
-
OPTIONS: 5,
|
|
16
|
-
TRACE: 6,
|
|
17
|
-
CONNECT: 7,
|
|
18
|
-
PATCH: 8
|
|
19
|
-
}
|
|
20
|
-
let libname;
|
|
21
|
-
if (process.platform === "win32") {
|
|
22
|
-
libname = "reqrio"
|
|
23
|
-
} else if (process.platform === "linux") {
|
|
24
|
-
libname = "libreqrio"
|
|
25
|
-
} else {
|
|
26
|
-
throw "unsupported system platform"
|
|
27
|
-
}
|
|
28
|
-
let libpath = path.join(__dirname, libname)
|
|
29
|
-
const library = ffi.Library(libpath, {
|
|
30
|
-
ScReq_new: [voidPtr, []],
|
|
31
|
-
ScReq_set_header_json: ['int', [voidPtr, charPtr]],
|
|
32
|
-
ScReq_add_header: ["int", [voidPtr, charPtr, charPtr]],
|
|
33
|
-
ScReq_set_alpn: ["int", [voidPtr, charPtr]],
|
|
34
|
-
ScReq_set_verify: ["int", [voidPtr, 'bool']],
|
|
35
|
-
ScReq_set_random_fingerprint: ["int", [voidPtr, charPtr]],
|
|
36
|
-
ScReq_set_fingerprint: ["int", [voidPtr, charPtr, charPtr]],
|
|
37
|
-
ScReq_set_ja3: ["int", [voidPtr, charPtr, charPtr]],
|
|
38
|
-
ScReq_set_ja4: ['int', [voidPtr, charPtr, charPtr]],
|
|
39
|
-
ScReq_set_proxy: ['int', [voidPtr, charPtr]],
|
|
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
|
-
make_ScReq_callback,
|
|
81
|
-
read_to_string
|
|
82
|
-
}
|
|
1
|
+
const ffi = require('ffi-napi');
|
|
2
|
+
const ref = require('ref-napi');
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const voidPtr = ref.refType(ref.types.void);
|
|
6
|
+
const charPtr = ref.types.CString;
|
|
7
|
+
const uint8Ptr = ref.refType(ref.types.uint8);
|
|
8
|
+
|
|
9
|
+
const Method = {
|
|
10
|
+
GET: 0,
|
|
11
|
+
POST: 1,
|
|
12
|
+
PUT: 2,
|
|
13
|
+
HEAD: 3,
|
|
14
|
+
DELETE: 4,
|
|
15
|
+
OPTIONS: 5,
|
|
16
|
+
TRACE: 6,
|
|
17
|
+
CONNECT: 7,
|
|
18
|
+
PATCH: 8
|
|
19
|
+
}
|
|
20
|
+
let libname;
|
|
21
|
+
if (process.platform === "win32") {
|
|
22
|
+
libname = "reqrio"
|
|
23
|
+
} else if (process.platform === "linux") {
|
|
24
|
+
libname = "libreqrio"
|
|
25
|
+
} else {
|
|
26
|
+
throw "unsupported system platform"
|
|
27
|
+
}
|
|
28
|
+
let libpath = path.join(__dirname, libname)
|
|
29
|
+
const library = ffi.Library(libpath, {
|
|
30
|
+
ScReq_new: [voidPtr, []],
|
|
31
|
+
ScReq_set_header_json: ['int', [voidPtr, charPtr]],
|
|
32
|
+
ScReq_add_header: ["int", [voidPtr, charPtr, charPtr]],
|
|
33
|
+
ScReq_set_alpn: ["int", [voidPtr, charPtr]],
|
|
34
|
+
ScReq_set_verify: ["int", [voidPtr, 'bool']],
|
|
35
|
+
ScReq_set_random_fingerprint: ["int", [voidPtr, charPtr]],
|
|
36
|
+
ScReq_set_fingerprint: ["int", [voidPtr, charPtr, charPtr]],
|
|
37
|
+
ScReq_set_ja3: ["int", [voidPtr, charPtr, charPtr]],
|
|
38
|
+
ScReq_set_ja4: ['int', [voidPtr, charPtr, charPtr]],
|
|
39
|
+
ScReq_set_proxy: ['int', [voidPtr, charPtr]],
|
|
40
|
+
ScReq_add_param: ['int', [voidPtr, charPtr, charPtr]],
|
|
41
|
+
ScReq_set_timeout: ["int", [voidPtr, charPtr]],
|
|
42
|
+
ScReq_set_cookie: ['int', [voidPtr, charPtr]],
|
|
43
|
+
ScReq_add_cookie: ['int', [voidPtr, charPtr, charPtr]],
|
|
44
|
+
ScReq_set_callback: ["int", [voidPtr, "pointer"]],
|
|
45
|
+
ScReq_reconnect: ['int', [voidPtr]],
|
|
46
|
+
ScReq_stream_io: ["pointer", [voidPtr, "int", charPtr, uint8Ptr, 'int', charPtr]],
|
|
47
|
+
ScReq_drop: ['int', [voidPtr]],
|
|
48
|
+
char_free: ['int', [charPtr]],
|
|
49
|
+
ws_build: [voidPtr, []],
|
|
50
|
+
ws_add_header: ['int', [voidPtr, charPtr, charPtr]],
|
|
51
|
+
ws_set_proxy: ['int', [voidPtr, charPtr]],
|
|
52
|
+
ws_set_url: ['int', [voidPtr, charPtr]],
|
|
53
|
+
ws_set_uri: ['int', [voidPtr, charPtr]],
|
|
54
|
+
ws_open: [voidPtr, [voidPtr]],
|
|
55
|
+
ws_open_raw: [voidPtr, [charPtr, charPtr]],
|
|
56
|
+
ws_read: ['pointer', [voidPtr]],
|
|
57
|
+
ws_write: ['int', [voidPtr, 'int', 'bool', charPtr]],
|
|
58
|
+
ws_close: ['int', [voidPtr]]
|
|
59
|
+
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
function make_ScReq_callback(func) {
|
|
63
|
+
return ffi.Callback("void", ["pointer", "uint32"], function (ptr, len) {
|
|
64
|
+
const buffer = ref.reinterpret(ptr, len);
|
|
65
|
+
const data = Buffer.from(buffer);
|
|
66
|
+
func(data)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function read_to_string(ptr) {
|
|
71
|
+
return ref.readCString(ptr, 0)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = {
|
|
75
|
+
library,
|
|
76
|
+
Method,
|
|
77
|
+
make_ScReq_callback,
|
|
78
|
+
read_to_string
|
|
79
|
+
}
|
package/libreqrio.so
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "reqrio",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A lightweight, high concurrency HTTP request library",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"http",
|
|
8
|
-
"lightweight",
|
|
9
|
-
"tls fingerprint"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/xllgl2017/reqrio.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "Apache-2.0",
|
|
19
|
-
"author": {
|
|
20
|
-
"name": "xllgl2017"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"ffi-napi": "^4.0.3",
|
|
24
|
-
"ref-napi": "^3.0.3"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "reqrio",
|
|
3
|
+
"version": "0.3.0-alpha4",
|
|
4
|
+
"description": "A lightweight, high concurrency HTTP request library",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"http",
|
|
8
|
+
"lightweight",
|
|
9
|
+
"tls fingerprint"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/xllgl2017/reqrio.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "xllgl2017"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"ffi-napi": "^4.0.3",
|
|
24
|
+
"ref-napi": "^3.0.3"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/reqrio.dll
CHANGED
|
Binary file
|
package/session.js
CHANGED
|
@@ -1,181 +1,183 @@
|
|
|
1
|
-
const {library, Method, make_ScReq_callback, read_to_string} = require("./bindings");
|
|
2
|
-
const {Response} = require("./Response")
|
|
3
|
-
|
|
4
|
-
const ALPN = Object.freeze({
|
|
5
|
-
HTTP10: "http/1.0",
|
|
6
|
-
HTTP11: "http/1.1",
|
|
7
|
-
HTTP20: "h2"
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
const registry = new FinalizationRegistry(req => {
|
|
11
|
-
library.ScReq_drop(req)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
class Session {
|
|
15
|
-
constructor(alpn, rand_tls, token, verify = true) {
|
|
16
|
-
this.req = library.ScReq_new();
|
|
17
|
-
if (alpn) {
|
|
18
|
-
let ret = library.ScReq_set_alpn(this.req, alpn)
|
|
19
|
-
if (ret === -1) throw "set_alpn error"
|
|
20
|
-
}
|
|
21
|
-
if (rand_tls && token) {
|
|
22
|
-
let ret = library.ScReq_set_random_fingerprint(this.req, token);
|
|
23
|
-
if (ret === -2) console.log("free user, set_random_fingerprint can't be used")
|
|
24
|
-
if (ret === -1) throw "set_random_fingerprint error"
|
|
25
|
-
}
|
|
26
|
-
library.ScReq_set_verify(this.req, verify)
|
|
27
|
-
registry.register(this, this.req)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
set_fingerprint(fingerprint, token) {
|
|
31
|
-
let ret = library.ScReq_set_fingerprint(this.req, fingerprint, token);
|
|
32
|
-
if (ret === -2) console.log("free user, set_fingerprint can't be used")
|
|
33
|
-
if (ret === -1) throw "set_fingerprint error"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set_ja3(ja3, token) {
|
|
37
|
-
let ret = library.ScReq_set_ja3(this.req, ja3, token);
|
|
38
|
-
if (ret === -2) console.log("free user, set_ja3 can't be used")
|
|
39
|
-
if (ret === -1) throw "set_ja3 error"
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
set_ja4(ja4, token) {
|
|
44
|
-
let ret = library.ScReq_set_ja4(this.req, ja4, token);
|
|
45
|
-
if (ret === -2) console.log("free user, set_ja4 can't be used")
|
|
46
|
-
if (ret === -1) throw "set_ja4 error"
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
set_headers(header) {
|
|
51
|
-
let header_str = JSON.stringify(header);
|
|
52
|
-
let ret = library.ScReq_set_header_json(this.req, header_str)
|
|
53
|
-
if (ret === -1) throw "set_header_json error"
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
add_header(name, value) {
|
|
57
|
-
let ret = library.ScReq_add_header(name, value)
|
|
58
|
-
if (ret === -1) throw "add_header error"
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
set_proxy(proxy) {
|
|
62
|
-
let ret = library.ScReq_set_proxy(this.req, proxy);
|
|
63
|
-
if (ret === -1) throw "add_header error"
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
let ret = library.
|
|
89
|
-
if (ret === -1) throw "
|
|
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
|
-
let
|
|
139
|
-
let
|
|
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
|
-
|
|
1
|
+
const {library, Method, make_ScReq_callback, read_to_string} = require("./bindings");
|
|
2
|
+
const {Response} = require("./Response")
|
|
3
|
+
|
|
4
|
+
const ALPN = Object.freeze({
|
|
5
|
+
HTTP10: "http/1.0",
|
|
6
|
+
HTTP11: "http/1.1",
|
|
7
|
+
HTTP20: "h2"
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const registry = new FinalizationRegistry(req => {
|
|
11
|
+
library.ScReq_drop(req)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
class Session {
|
|
15
|
+
constructor(alpn, rand_tls, token, verify = true) {
|
|
16
|
+
this.req = library.ScReq_new();
|
|
17
|
+
if (alpn) {
|
|
18
|
+
let ret = library.ScReq_set_alpn(this.req, alpn)
|
|
19
|
+
if (ret === -1) throw "set_alpn error"
|
|
20
|
+
}
|
|
21
|
+
if (rand_tls && token) {
|
|
22
|
+
let ret = library.ScReq_set_random_fingerprint(this.req, token);
|
|
23
|
+
if (ret === -2) console.log("free user, set_random_fingerprint can't be used")
|
|
24
|
+
if (ret === -1) throw "set_random_fingerprint error"
|
|
25
|
+
}
|
|
26
|
+
library.ScReq_set_verify(this.req, verify)
|
|
27
|
+
registry.register(this, this.req)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set_fingerprint(fingerprint, token) {
|
|
31
|
+
let ret = library.ScReq_set_fingerprint(this.req, fingerprint, token);
|
|
32
|
+
if (ret === -2) console.log("free user, set_fingerprint can't be used")
|
|
33
|
+
if (ret === -1) throw "set_fingerprint error"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
set_ja3(ja3, token) {
|
|
37
|
+
let ret = library.ScReq_set_ja3(this.req, ja3, token);
|
|
38
|
+
if (ret === -2) console.log("free user, set_ja3 can't be used")
|
|
39
|
+
if (ret === -1) throw "set_ja3 error"
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set_ja4(ja4, token) {
|
|
44
|
+
let ret = library.ScReq_set_ja4(this.req, ja4, token);
|
|
45
|
+
if (ret === -2) console.log("free user, set_ja4 can't be used")
|
|
46
|
+
if (ret === -1) throw "set_ja4 error"
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
set_headers(header) {
|
|
51
|
+
let header_str = JSON.stringify(header);
|
|
52
|
+
let ret = library.ScReq_set_header_json(this.req, header_str)
|
|
53
|
+
if (ret === -1) throw "set_header_json error"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
add_header(name, value) {
|
|
57
|
+
let ret = library.ScReq_add_header(name, value)
|
|
58
|
+
if (ret === -1) throw "add_header error"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
set_proxy(proxy) {
|
|
62
|
+
let ret = library.ScReq_set_proxy(this.req, proxy);
|
|
63
|
+
if (ret === -1) throw "add_header error"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
add_param(name, value) {
|
|
67
|
+
let ret = library.ScReq_add_param(this.req, name, value);
|
|
68
|
+
if (ret === -1) throw "add_param error"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
Timeout{
|
|
73
|
+
connect:3000,
|
|
74
|
+
read:3000,
|
|
75
|
+
write:3000,
|
|
76
|
+
handle:30000,
|
|
77
|
+
connect_times:3,
|
|
78
|
+
handle_times:3
|
|
79
|
+
}
|
|
80
|
+
*/
|
|
81
|
+
set_timeout(timeout) {
|
|
82
|
+
let timeout_str = JSON.stringify(timeout);
|
|
83
|
+
let ret = library.ScReq_set_timeout(this.req, timeout_str);
|
|
84
|
+
if (ret === -1) throw "set_timeout error"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
set_cookie(cookie) {
|
|
88
|
+
let ret = library.ScReq_set_cookie(this.req, cookie)
|
|
89
|
+
if (ret === -1) throw "set_cookie error"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
add_cookie(name, value) {
|
|
93
|
+
let ret = library.ScReq_add_cookie(this.req, name, value)
|
|
94
|
+
if (ret === -1) throw "add_cookie error"
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
reconnect() {
|
|
98
|
+
let ret = library.ScReq_reconnect(this.req)
|
|
99
|
+
if (ret === -1) throw "reconnect error"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
set_callback(func) {
|
|
103
|
+
let callback = make_ScReq_callback(func)
|
|
104
|
+
library.ScReq_set_callback(this.req, callback)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_format_body(data, json, bytes, ct) {
|
|
108
|
+
if (data !== null) {
|
|
109
|
+
let keys = Object.keys(data)
|
|
110
|
+
let res = "";
|
|
111
|
+
for (let i = 0; i < keys.length; i++) {
|
|
112
|
+
res += keys[i];
|
|
113
|
+
res += "="
|
|
114
|
+
res += encodeURIComponent(JSON.stringify(data[keys[i]]))
|
|
115
|
+
res += "&"
|
|
116
|
+
}
|
|
117
|
+
if (res.endsWith("&")) {
|
|
118
|
+
res = res.substring(0, res.length - 1)
|
|
119
|
+
}
|
|
120
|
+
if (ct === null)
|
|
121
|
+
return [new TextEncoder().encode(res), "application/x-www-form-urlencoded"]
|
|
122
|
+
else return [new TextEncoder().encode(res), ct]
|
|
123
|
+
}
|
|
124
|
+
if (json !== null) {
|
|
125
|
+
let res = JSON.stringify(json);
|
|
126
|
+
if (ct === null)
|
|
127
|
+
return [new TextEncoder().encode(res), "application/json"]
|
|
128
|
+
else return [new TextEncoder().encode(res), ct]
|
|
129
|
+
}
|
|
130
|
+
if (bytes !== null)
|
|
131
|
+
if (ct === null)
|
|
132
|
+
return [bytes, "application/octet-stream"]
|
|
133
|
+
else return [bytes, ct]
|
|
134
|
+
return [new TextEncoder().encode(""), "application/octet-stream"]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
send(method, url, data, json, bytes, ct) {
|
|
138
|
+
let body = this._format_body(data, json, bytes, ct)
|
|
139
|
+
let resp = library.ScReq_stream_io(this.req, method, url, body[0], body[0].length, body[1])
|
|
140
|
+
let buffer = Buffer.from(read_to_string(resp), "hex");
|
|
141
|
+
let response = new Response(buffer);
|
|
142
|
+
response.header.method = method;
|
|
143
|
+
library.char_free(resp)//;这里需要手动释放吗
|
|
144
|
+
return response;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
get(url, data, json, bytes, ct) {
|
|
148
|
+
return this.send(Method.GET, url, data, json, bytes, ct)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
post(url, data, json, bytes, ct) {
|
|
152
|
+
return this.send(Method.POST, url, data, json, bytes, ct)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
options(url, data, json, bytes, ct) {
|
|
156
|
+
return this.send(Method.OPTIONS, url, data, json, bytes, ct)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
head(url, data, json, bytes, ct) {
|
|
160
|
+
return this.send(Method.HEAD, url, data, json, bytes, ct)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
trace(url, data, json, bytes, ct) {
|
|
164
|
+
return this.send(Method.TRACE, url, data, json, bytes, ct)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
delete(url, data, json, bytes, ct) {
|
|
168
|
+
return this.send(Method.DELETE, url, data, json, bytes, ct)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
patch(url, data, json, bytes, ct) {
|
|
172
|
+
return this.send(Method.PATCH, url, data, json, bytes, ct)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
close() {
|
|
176
|
+
registry.unregister(this);
|
|
177
|
+
library.ScReq_drop(this.req)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = {
|
|
182
|
+
Session, ALPN, Method, Response
|
|
181
183
|
}
|
package/test.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
const {Session, ALPN, Websocket} = require('./index')
|
|
2
|
-
|
|
3
|
-
let session = new Session(ALPN.HTTP20, true, "sd", false);
|
|
4
|
-
session.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ws.set_url("wss://alive.github.com")
|
|
17
|
-
ws.open()
|
|
1
|
+
const {Session, ALPN, Websocket} = require('./index')
|
|
2
|
+
|
|
3
|
+
let session = new Session(ALPN.HTTP20, true, "sd", false);
|
|
4
|
+
session.set_callback(function (data) {
|
|
5
|
+
console.log(data.length)
|
|
6
|
+
})
|
|
7
|
+
let resp = session.get("https://m.so.com", null, null, new TextEncoder().encode("sdfdgdfg"), "text/plain");
|
|
8
|
+
console.log(resp.status_code())
|
|
9
|
+
console.log(resp.header)
|
|
10
|
+
session.close();
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
let ws = new Websocket();
|
|
14
|
+
ws.set_url("wss://alive.github.com")
|
|
15
|
+
ws.open()
|
|
18
16
|
ws.read()
|
package/ws.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
const {library, read_to_string} = require("./bindings");
|
|
2
|
-
const registry = new FinalizationRegistry(ws => {
|
|
3
|
-
library.ws_close(ws)
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
class Websocket {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.build = library.ws_build();
|
|
9
|
-
this.ws = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
add_header(name, value) {
|
|
13
|
-
let ret = library.ws_add_header(this.build, name, value)
|
|
14
|
-
if (ret === -1) throw "add header error"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set_proxy(proxy) {
|
|
18
|
-
let ret = library.ws_set_proxy(this.build, proxy);
|
|
19
|
-
if (ret === -1) throw "set proxy error"
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
set_url(url) {
|
|
23
|
-
let ret = library.ws_set_url(this.build, url)
|
|
24
|
-
if (ret === -1) throw "set url error"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
set_uri(uri) {
|
|
28
|
-
let ret = library.ws_set_uri(this.build, uri)
|
|
29
|
-
if (ret === -1) throw "set uri error"
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
open(url) {
|
|
33
|
-
if (url) this.set_url(url)
|
|
34
|
-
this.ws = library.ws_open(this.build)
|
|
35
|
-
if (!this.ws || this.ws.length === 0) throw "connect error"
|
|
36
|
-
registry.register(this, this.ws)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
read() {
|
|
40
|
-
let ptr = library.ws_read(this.ws)
|
|
41
|
-
let s = read_to_string(ptr)
|
|
42
|
-
library.char_free(ptr)
|
|
43
|
-
return JSON.parse(s)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
write(opcode, mask, msg) {
|
|
47
|
-
let ret = library.ws_write(this.ws, opcode, mask, msg)
|
|
48
|
-
if (ret === -1) throw "ws write error"
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
close() {
|
|
52
|
-
registry.unregister(this);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
module.exports = {
|
|
58
|
-
Websocket
|
|
1
|
+
const {library, read_to_string} = require("./bindings");
|
|
2
|
+
const registry = new FinalizationRegistry(ws => {
|
|
3
|
+
library.ws_close(ws)
|
|
4
|
+
})
|
|
5
|
+
|
|
6
|
+
class Websocket {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.build = library.ws_build();
|
|
9
|
+
this.ws = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
add_header(name, value) {
|
|
13
|
+
let ret = library.ws_add_header(this.build, name, value)
|
|
14
|
+
if (ret === -1) throw "add header error"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set_proxy(proxy) {
|
|
18
|
+
let ret = library.ws_set_proxy(this.build, proxy);
|
|
19
|
+
if (ret === -1) throw "set proxy error"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
set_url(url) {
|
|
23
|
+
let ret = library.ws_set_url(this.build, url)
|
|
24
|
+
if (ret === -1) throw "set url error"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set_uri(uri) {
|
|
28
|
+
let ret = library.ws_set_uri(this.build, uri)
|
|
29
|
+
if (ret === -1) throw "set uri error"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
open(url) {
|
|
33
|
+
if (url) this.set_url(url)
|
|
34
|
+
this.ws = library.ws_open(this.build)
|
|
35
|
+
if (!this.ws || this.ws.length === 0) throw "connect error"
|
|
36
|
+
registry.register(this, this.ws)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
read() {
|
|
40
|
+
let ptr = library.ws_read(this.ws)
|
|
41
|
+
let s = read_to_string(ptr)
|
|
42
|
+
library.char_free(ptr)
|
|
43
|
+
return JSON.parse(s)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
write(opcode, mask, msg) {
|
|
47
|
+
let ret = library.ws_write(this.ws, opcode, mask, msg)
|
|
48
|
+
if (ret === -1) throw "ws write error"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
close() {
|
|
52
|
+
registry.unregister(this);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
Websocket
|
|
59
59
|
}
|
package/2.log
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
CLIENT_RANDOM 23d64b6e81b87a9c7fe0ec34e0f58894bea139a98e8b196df3f3dc7b67f248b8 afdbccc075aa3059049c3a19f01708ad1cb824f84a9debd4caec92f22738d1b5b67130ab694f19942acce5820e5b8354
|
|
2
|
-
CLIENT_RANDOM 3e8e438c78f16006147c74c27b7686d993f3c6291b19277d44c2188a0adf921f 734519038b5ac91324cd35e8bad70ba645fbafb35f03ace06423c1589924163cc7391cde7836fb908a1178c92db2a711
|
|
3
|
-
CLIENT_RANDOM 492ab0fa7bdd8b3d7482d15edfba71268198860ee750d4c9dd8774138a266474 444d17796592c8ef3910d62322bf4de1ca064cd51e9e5d2b394db49d812f86bdb101995c2227209cc889da482f06b9fb
|
|
4
|
-
CLIENT_RANDOM 7ac8f16a3b7a542f0264855aeb4a8537cda849697a91906711f6ed00df848b23 29b43ab6277cd38c07d50cd1421324016872ce7845c3501b4ad1ec44ec961875e8576ccd1c277e93877086ec7bef0062
|
|
5
|
-
CLIENT_RANDOM 38fa7ae097512a1216dbc49f6ac9bb538a1aab24827bd668782d6358f182bed7 9eab59c3bbb730867646fb21122251e5f7098e4af6790a7d90dc17fcf8f375f866b5e1d41c79a2b43dc88917dcfdf9b7
|
|
6
|
-
CLIENT_RANDOM 326fd0629200a271572bddfe6e9c09504d962a8bab491b2526b660b5f52009e2 b0a0dd52d4f0513a152da8347d6a1b4175b46dba445f925c2bb9b728eb4a23420fee98f343784d1dcb5ae50ebb6773d6
|
|
7
|
-
CLIENT_RANDOM fd2f812783ecfe4fa0ab35dcd04b1b4d31407d1999f10807b63076f1074f8b35 3d2d68db48dc4460db3d0087d0339a11a153df66b03dc2cb1951d23e790743c67f7bacd55355dc6f3a7860f0f5bb7cad
|
|
8
|
-
CLIENT_RANDOM ec26475e0a50cb603d73136b9590094b57cef7634a00def88e06333f11653ab3 d638173adf04099f43457be7973ad69db47263b51dde9c569310d04d89b7f0c036271889e3110cefe5ce0652abd7ad4a
|
|
9
|
-
CLIENT_RANDOM 2d748711a0efe6ef01298940286c91589624fbeaaf021f30f05f84733100b2cb 43a6086b9e01cb2829e75487c42d739bf85c8318b5569691ac5a8f2ee00fb21a1aa9700cfdc852dab6ed40d2f25fb297
|
|
10
|
-
CLIENT_RANDOM 7021d613e187e1dab2f4fa81d649488cdc02fb18e53d08366cec9e35209064ff 9d3a2e71c0690e33a8eadbe757b50d417b1bd90e85a839ac313606d919473ca1fa304053ce3d0afad2fd91a27f1d6f65
|
|
11
|
-
CLIENT_RANDOM 81744e18f95d095000a06c778920ae0724bb2b9346980c9b2d878eae4a05fe3d 0f5b23919a5fe340f3e0e5a8dd8d632df5e4fa585ad203d8dd54ebc6a82a59ab8ae8c75309cb282f07eb20c36e6865a8
|
|
12
|
-
CLIENT_RANDOM 134ef883b5cf904e67d51334da73b7961e2d08a697228c594c3f80d961ead34b 5ec6e8a546232b8b22fb5d693b77ecf5c1e8b3366d904b1be902823728e8244246388924bcbcc628c157f463d21e64a5
|
|
13
|
-
CLIENT_RANDOM 2700323df89d611e59dbf1ae61873f88d1a48885774c75216e64d3a37f50ac74 3e5198d9d76193cf09da6de5dcecf0a589a2520d4bbe353ee96ce9ae69690738ee5d37f0ec4cedbb1c49d05be6457de0
|
|
14
|
-
CLIENT_RANDOM 64cabd941d38cbc2d42510955b6903a0c9a18e24b7a0d20d951da28a411c1f2d 45a6e3c9949865c07d2ee691dcbf52071c60a8f1c2c8d6d911bc1618236c344b8b5c55a9f63f3586d9f06e2360cb60cb
|
|
15
|
-
CLIENT_RANDOM 33163efd14700c28e313722dab4a9864dc201bf719a7157c67b4648cd8a6644e f743544daab2b746faceb2dd9eeb3a7fefedf303622532b87407bb62b653850a4a0931504fe67f3794089c67b4428704
|
|
16
|
-
CLIENT_RANDOM 57916ccb53982b375d58aeec462c6168e4b71f253bd697e4f007158788b04121 01b93f1eeae846fd6dba75a737e99d0d5b34932dcd4db9321b3c3277b17fd5d077e6f8d7b70600a6ee4efdc63312c2e8
|
|
17
|
-
CLIENT_RANDOM ea5508bbbbda64ec3779eb8950404fb02d8af2c2d84caec2ae1eda14a4ddcfa1 ad00b59f9099bf59ba01931a822a5d32544b41e5eb9f98ead2207ed46dd3aa6828e6be5188d23cfbf9059740976ebff8
|
|
18
|
-
CLIENT_RANDOM f85c60d14cbe71da97163b827412553c660318b0de368e2b5837fd12488bbfb8 528f9475110304e72be4fae79fca81158007a461402453d83c823605337753432b8bd0b0eb08a430a7399ca84bd8981f
|
|
19
|
-
CLIENT_RANDOM 503b01a3e2e33181bff1e09075ee01fd18750e09065086ce895fc93be5bb5e30 a642c912bce0ad3450294e12a525b48d5f4badfd02f4b7959906ac4242815e16d074f54ca216152bc99efd56dcfe0a38
|
|
20
|
-
CLIENT_RANDOM 9ea25a0407ffeab403cecd84aa0f461394d8e00167197353658b330924c07866 cf6a7c238fee1203f6b65dafa3817c5a6658efb22bbe369228b3acab67a4ad31ece9e01848358be82d83cd1819b4776c
|
|
21
|
-
CLIENT_RANDOM 8091d78ce9f9fd8d3b425edab68dade8733289d4cd2df3d3d1bf4113b5a34159 f316c8fa7fe8f0133e891c7df7a87a8fdecacd3163abdb828f5bfceb2b656ee8c42eb8896669aebe4e9cf2c6c2599b65
|
|
22
|
-
CLIENT_RANDOM 1055e19490a6c9eaba6128978d9351df41244fc34e6e38879453ad8f5a96e0b9 18c54a03e630e77509a444f86b990855290da83e2b5f4476b3080a3ac11ec620f278c74d895eba6dd2b8450ca2eeb149
|
|
23
|
-
CLIENT_RANDOM 2db982e46c3c7aa149b440640d8207b482c1439f261a8222439c07b8ef582203 a1750292c392ae77c8fb4d3ee36c04b30b2ae48afac9d45163208f48228cc0b6665a0386e373fbdbf841822ddf5f7bb3
|
|
24
|
-
CLIENT_RANDOM 82c47384d405a3504e31175c005b397e782559ca231466270a8f715fa1caed30 fe4051c68eb0890344aa72dcbc9a1bef2613a60e94c9bc36945a51fd31ce7aa3f7a011a3c5104ab4ea79d3eda44dc04a
|
|
25
|
-
CLIENT_RANDOM d89265054fb145fe75fe56e224a0aac9acd23a87221c95a7b5bc0d2f94945750 abb0e3d6951e49a609497f6a0895dcdaf527accbc344ac90833e7d14f93a5c2224588830f702c6ee9859a8510ec48562
|
|
26
|
-
CLIENT_RANDOM c2afc383b0363f37dd448ef95aa30a8c12ec8f515e321679f70b37cd82f74836 e0bde036e403ae0cd4111db98b4ef6ee82634faccf0414392ab782ccd88e7cefe6d66db6995f5aa18f7e0a96c582b409
|
|
27
|
-
CLIENT_RANDOM b009e5252d97d5086723bf3ed3788000c167900c6f060449feaf2262045f69df 673f5759883a46a6f0116266a2ca24f5c217cb96360bd42ec244ad282fb92d1e636db9e438b61edae05541effdce6c60
|
|
28
|
-
CLIENT_RANDOM 547e11d441719d61c836cdd53f55a0828cbf9c8b1dfb7da104f890f16c2ac781 e6e67b5ea27eca02afeaee0786b285c33c90531c4e8c4b6e72c90e6897c4c66fc6c7c5305eec14e37414094a43f67adf
|
|
29
|
-
CLIENT_RANDOM 622c86402ae3439f0cf70aa614f8be142f221006dae4f12cfb3f77381d770e86 431c70971d631a265a863d39466bd1c29bc2de9c7e07aadf52c22bb556021308213cc920819b7360455344832c223adf
|
|
30
|
-
CLIENT_RANDOM 7f80dcd4bea6bbd923d31957b971374657980c3ca82177ab2fac70da8df2d39d 8e0cb6dbbe19e3dcd45fafd416fb5ab8d66a9cd4da24e2e03f38464e5e94dac58c329837b16ec7201712422523aa63d6
|
|
31
|
-
CLIENT_RANDOM 7ef0b7e7eb064374dd8652a23cd512099314453fa4a6df5f4bd9bc595b27ba77 b07f474bba1a40e39f97920251674e378cef38ee3ea1d4dab7d66cc834e126c9dbd7a77c341fc7c7182364f230752c2a
|
|
32
|
-
CLIENT_RANDOM ed71850a389c5f29eecb1cac882d0e62ce9b55dfc8bdc7404e2f3d2ffa9aaa31 080f7b03f5c49a12cc1927e0c3723e682eefd1d9f5d833ed211fceace61f7f3415fcc1e6689fda2d4efb8554ad7eaa71
|
|
33
|
-
CLIENT_RANDOM 6519336c53f75305cc1219d2e26379f2e81dd8a4f4bacc324305a561df6a94d7 c5c04fb38483c08046bd80f2b5749d1c88f84d016bbf1c38a3b84a77e92ef23f2c81829386ac89016de86a91f0bef7b2
|
|
34
|
-
CLIENT_RANDOM 09647f892d211ce87245475a18dfb8466847a994e9b971e10a293b0d9a630bd9 a94afea9447ee119432d21c850f1dea431926ab4168c8ce6f1b03daf0852fcf436a668b4843088b9cc698884a6b9a5e1
|
|
35
|
-
CLIENT_RANDOM 40c4a4038db16498b18defb475f76eb960fab4d7c3cb614e6e1f7992df9e98f0 411fdd4cc4176ec2efc23f0b07c935b9bf72ee3e4997b572b3a7e6faffb196daab9277a32c037b81b3f645a7434abe8a
|
|
36
|
-
CLIENT_RANDOM 966ed32241c38b1d168bc87b4789e52401c588746c4ad42e29975d0ff49b363c c5a52901916cd4c993e7f774b97174d4cef2a1be24f3cf0675ab866b80dab69140f290a99dd3c307ac6dbeb01f4e4ead
|
|
37
|
-
CLIENT_RANDOM 6f71074305989527086d8ebce133d155a85b232bdc474f9fb1e18aa005031adb ad1d2821354848d10703f04647ca324438fc5e2df60639b3db89082f0995590f0d88ac9d613039a7e885eb97ad9392c9
|
|
38
|
-
CLIENT_RANDOM 58329af12e3a0c20da02cd91e8add6cff9e296e6432791f77afdc02c6e2c8189 833119fc15c1d797632bd86ba840f1bcbe8214e8e7a88ab46881b6d388f735d268045f19902a694cda9aa9c85f3c4d86
|
|
39
|
-
CLIENT_RANDOM 57ebe1865008502c2eee11b6419166ecbbe2d6408ea988b2b9e42ec08b12c2ff c3f0e97fa83edc2944cf637865aa0bd212fc3bf9f081c6a7a382cfbd6bab14224ca8ebf49fc6cf82adf96240e44686c6
|
|
40
|
-
CLIENT_RANDOM 2b18740baa2ae2d6dfce9ac88e71ca49532d8b5bdd4ceed0fa83bce652b699c5 3e025245ee0a2daf5524dd657df695e35880099e8d235ed26515db97903003e3412ef30a0e7f2639ca0868692ee4c382
|
|
41
|
-
CLIENT_RANDOM d1e0c818e88c5e01fadfe05b8895ab54348ff3d7f8109e267ac404088f834221 37deaf63f7c91645ef2bfd70a8f861e637460103e3713dbc8a8eab353bc0f58ef73c871b050455d2bcc5802817da4193
|
|
42
|
-
CLIENT_RANDOM 485a849f8ef01449b464211c26aab0fc33f7dfc4e89b7f2b8704adc3884a42b4 81b7344cf7d796fd0f14cffcccb171eae634a7ef33eb3a07f06201ced0fa8332e1dea461feb031ba69f448f68d056950
|
|
43
|
-
CLIENT_RANDOM d36388c2674bc82f9f55e6e5ba75a486d88f36dfe2059a2dddd51a399ac620b8 d1c4eab2faf6bc61c4e596ca26a0f49cb5b592ea72344ba4b6410aa452fecebd0a0277e8caf51912a0423ab0f0b7f9cc
|
|
44
|
-
CLIENT_RANDOM ba15d711142d8f0f0211f740e88b8614d2ab56c5680e89468e251e844bc937fd 8012359c5503ff84daffc5a06ddb6a36b880330904d98bc81aa28eb7e9d025d494f89ea90d9b409e0c6a976baa8323bd
|
|
45
|
-
CLIENT_RANDOM 62f0ce35f475bcbc4fae7c801fb33851ea426c7d30c0f3921c9957436deca650 49fdfcadcb85e715917d9c4092903e0f0a85d6f8484c22e656a0f2697e1ab4eb1d969d341bc5935e32bcc8649aa73c92
|
|
46
|
-
CLIENT_RANDOM e134d881cb0a5067ac6af15f73301b731b40b3d06571b6f1f324de6c11298ab1 810a47ec88e22aae41f8c937d315a55e396f0cbff8c6123497d7635b747dfde7de61c60479d7ecc8eb679c54a13019ff
|
|
47
|
-
CLIENT_RANDOM 79a5bff0bea3d6a18f13c21a9dbd31a9e4c3bb3ed29f619aeede6cb9a95d96ce d6101810d457ed4c60a3bf59f09fe6d0f2ea3d46d6f7087434d2bcd74257d7a924639d7a8bd1f906c7ff46c9c5414fbb
|