@chenshunyu/proxy 1.0.0-beta.30
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 +63 -0
- package/headers.env.txt +15 -0
- package/help.png +0 -0
- package/index.js +113 -0
- package/package.json +20 -0
- package/publish.bat +1 -0
- package/publish.npmjs.org.bat +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
`@chenshunyu/proxy` is a lightweight HTTP proxy server designed to help developers easily modify HTTP request headers for testing and debugging network requests.
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
Install `@chenshunyu/proxy` via npm:
|
|
5
|
+
```bash
|
|
6
|
+
npm i @chenshunyu/proxy
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
Start the proxy server:
|
|
11
|
+
```bash
|
|
12
|
+
node node_modules/@chenshunyu/proxy --port 8080 --file headers.txt
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Parameters
|
|
16
|
+
- --port: Specifies the port number the proxy server listens on. Default is 8080.
|
|
17
|
+
|
|
18
|
+
- --file: Specifies the path to the file containing request header information. The file format should be key-value pairs, one per line, for example:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
GET /example/path HTTP/1.1
|
|
22
|
+
key1: value1
|
|
23
|
+
key2: value2
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Getting the Request Header File
|
|
27
|
+
1. Open the browser developer tools (usually by pressing F12 or right-clicking and selecting "Inspect").
|
|
28
|
+
1. Go to the "Network" tab.
|
|
29
|
+
1. Right-click any request and select "Copy" -> "Copy request headers".<br>
|
|
30
|
+

|
|
31
|
+
1. Paste the copied content into a text file and save it as `headers.txt`.
|
|
32
|
+
|
|
33
|
+
### Request Expiration
|
|
34
|
+
When a request expires, you can continue using the proxy service by updating the `headers.txt` file.
|
|
35
|
+
|
|
36
|
+
### Usage Security Recommendation
|
|
37
|
+
For security purposes, it's strongly recommended to add `headers.txt` to your `.gitignore`/`.npmignore` files. This prevents accidental exposure of sensitive headers (like cookies or tokens) in version control systems.
|
|
38
|
+
|
|
39
|
+
Example `.gitignore` entry:
|
|
40
|
+
```diff
|
|
41
|
+
+ # Ignore proxy header files
|
|
42
|
+
+ headers.txt
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Example
|
|
46
|
+
Assume you have a file named `headers.txt` with the following content:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
GET /example/path HTTP/1.1
|
|
50
|
+
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
|
|
51
|
+
Accept-Language: en-US,en;q=0.9
|
|
52
|
+
Cookie: session=abc123; user=JohnDoe
|
|
53
|
+
Host: example.com
|
|
54
|
+
Referer: https://example.com/login
|
|
55
|
+
X-CSRF-TOKEN: abcdef123456
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Start the proxy server:
|
|
59
|
+
```bash
|
|
60
|
+
node node_modules/@chenshunyu/proxy --port 8080 --file headers.txt
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Now, the proxy server will run on port 8080 and use the request header information from the `headers.txt` file. If the request expires, update the `headers.txt` file.
|
package/headers.env.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
POST /post HTTP/1.1
|
|
2
|
+
Accept-Encoding: gzip, deflate, br, zstd
|
|
3
|
+
Accept-Language: en-US,en;q=0.9
|
|
4
|
+
Connection: keep-alive
|
|
5
|
+
Content-Length: 0
|
|
6
|
+
Host: httpbin.org
|
|
7
|
+
Referer: https://httpbin.org/
|
|
8
|
+
Sec-Fetch-Dest: empty
|
|
9
|
+
Sec-Fetch-Mode: cors
|
|
10
|
+
Sec-Fetch-Site: same-origin
|
|
11
|
+
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
|
|
12
|
+
accept: application/json
|
|
13
|
+
sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"
|
|
14
|
+
sec-ch-ua-mobile: ?0
|
|
15
|
+
sec-ch-ua-platform: "Windows"
|
package/help.png
ADDED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
const httpProxy = require('http-proxy');
|
|
4
|
+
|
|
5
|
+
var args = process.argv.slice(2);
|
|
6
|
+
var port = 0
|
|
7
|
+
var filePath = null
|
|
8
|
+
var close = null
|
|
9
|
+
var watching = false
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < args.length; i++) {
|
|
12
|
+
if (args[i] === '--port') {
|
|
13
|
+
port = parseInt(args[i + 1]);
|
|
14
|
+
}
|
|
15
|
+
if (args[i] === '--file') {
|
|
16
|
+
filePath = args[i + 1];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if(filePath) {
|
|
21
|
+
read()
|
|
22
|
+
} else {
|
|
23
|
+
console.error('No file input, try to use command like: --file headers.txt')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function read() {
|
|
27
|
+
fs.readFile(filePath, 'utf-8', (err, data) => {
|
|
28
|
+
if (err) {
|
|
29
|
+
console.error('File read fail:', err);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let lines = data.split('\n');
|
|
34
|
+
let headers = {};
|
|
35
|
+
|
|
36
|
+
for (let i = 1; i < lines.length; i++) {
|
|
37
|
+
let line = lines[i].trim();
|
|
38
|
+
if (line === '') continue;
|
|
39
|
+
|
|
40
|
+
let [key, value] = line.split(': ');
|
|
41
|
+
if (key && value) {
|
|
42
|
+
headers[key] = value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
close = create(headers)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function create(allHeaders) {
|
|
51
|
+
let {
|
|
52
|
+
protocol,
|
|
53
|
+
host,
|
|
54
|
+
} = new URL(allHeaders.Referer)
|
|
55
|
+
|
|
56
|
+
let target = `${protocol}//${host}`
|
|
57
|
+
console.table({
|
|
58
|
+
target,
|
|
59
|
+
Referer: allHeaders.Referer,
|
|
60
|
+
Host: allHeaders.Host,
|
|
61
|
+
'X-CSRF-TOKEN': allHeaders['X-CSRF-TOKEN'],
|
|
62
|
+
})
|
|
63
|
+
console.log('Cookie:\x1b[34m%s\x1b[0m', allHeaders.Cookie)
|
|
64
|
+
|
|
65
|
+
let proxy = httpProxy.createProxyServer({});
|
|
66
|
+
let server = http.createServer((req, res) => {
|
|
67
|
+
proxy.web(req, res, {
|
|
68
|
+
target,
|
|
69
|
+
secure: false,
|
|
70
|
+
changeOrigin: true,
|
|
71
|
+
cookieDomainRewrite: host,
|
|
72
|
+
headers: {
|
|
73
|
+
Referer: allHeaders.Referer,
|
|
74
|
+
Host: allHeaders.Host,
|
|
75
|
+
Cookie: allHeaders.Cookie??null,
|
|
76
|
+
'X-CSRF-TOKEN': allHeaders['X-CSRF-TOKEN']??null,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
proxy.on('error', e => {
|
|
82
|
+
console.warn(`Proxy error:`)
|
|
83
|
+
console.error(e)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
start(server)
|
|
87
|
+
|
|
88
|
+
return function close() {
|
|
89
|
+
proxy.close()
|
|
90
|
+
server.close()
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function start(server) {
|
|
95
|
+
server.listen(port, () => {
|
|
96
|
+
console.log(`Proxy server is running on port ${port}`);
|
|
97
|
+
if(!watching) {
|
|
98
|
+
watch()
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function watch() {
|
|
104
|
+
console.log('Watching...')
|
|
105
|
+
watching = true
|
|
106
|
+
fs.watch(filePath, e => {
|
|
107
|
+
if (e === 'change') {
|
|
108
|
+
console.log('File changes, reload...');
|
|
109
|
+
close?.()
|
|
110
|
+
read();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chenshunyu/proxy",
|
|
3
|
+
"version": "1.0.0-beta.30",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"bin": {
|
|
10
|
+
"proxy": "index.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "node index.js --port 8080 --file headers.env.txt"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"http-proxy": "^1.18.1"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/publish.bat
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
start "publish" npm publish
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
start "publish" npm publish --registry=https://registry.npmjs.org
|