Forgot password?
 Register account
View 649|Reply 7

[NodeJs] proxy

[Copy link]

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

hbghlyj Posted 2022-8-17 22:44 |Read mode
Last edited by hbghlyj 2022-9-5 14:46
  1. #!/usr/bin/env node
  2. "use strict";
  3. var http = require('http');
  4. http.createServer(function (client_req, client_res) {
  5.   console.log('serve: ' + client_req.url);
  6.   const options = {
  7.     hostname: 'kuing.infinityfreeapp.com',
  8.     path: client_req.url,
  9.     method: client_req.method,
  10.     headers: {
  11.       'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0',
  12.       'cookie':'__test=bf16be7e1cad023ea994c34ab6f950cb;'
  13.     }
  14.   };
  15.   http.request(options, function (response) {
  16.     let headers = response.headers;
  17.     if(headers['location'])
  18.     headers['location']=headers['location'].replace('kuing.infinityfreeapp.com','cjhb.site:3001');
  19.     switch(response.headers['content-type'].slice(0,9)){
  20.       case 'text/html':
  21.         client_res.writeHead(response.statusCode, headers);
  22.         var str = '';
  23.         response.on('data', function (chunk) {
  24.           str += chunk;
  25.         });   
  26.         response.on('end', function () {
  27.           client_res.end(str.replaceAll('src="https://kuing.cjhb.site','src="http://cjhb.site:3001'));
  28.         });
  29.         break;
  30.       case 'text/css':
  31.         var str = '';
  32.         response.on('data', function (chunk) {
  33.           str += chunk;
  34.         });   
  35.         response.on('end', function () {
  36.           str = str.replaceAll('kuing.infinityfreeapp.com','cjhb.site:3001').replace(/url\(([^"\)]+)/g,'url("$1"');
  37.           if(headers['content-length'])
  38.           headers['content-length']=Buffer.byteLength(str);
  39.           client_res.writeHead(response.statusCode, headers);
  40.           client_res.end(str);
  41.         });
  42.         break;
  43.       default:
  44.         client_res.writeHead(response.statusCode, headers);
  45.         response.pipe(client_res, {end: true});
  46.     }
  47.   }).end();
  48. }).listen(3001);
Copy the Code

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-8-17 23:26
Last edited by hbghlyj 2022-8-18 03:53可以测试一下:
cjhb.site:3001
一个难点: Web Archive bot在有附件的帖子,不会自动下载附件,必须另外保存下载附件的URL. 话说, DiscuzX的“附件ID”是不变的吗? @kuing

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-8-18 10:40
Last edited by hbghlyj 2022-8-19 17:13我发现会随机产生一些损坏的字符, 显示为 Unicode replacement character �(65533, U+FFFD)
Screenshot 2022-08-18 at 02-49-20 Editing Note 2 - Snip Notes.png
Screenshot 2022-08-18 at 02-49-20 Editing Note 2 - Snip Notes.png main-modified.png

是因为1#的代码没有gzip compress再发送响应吗?

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-8-19 04:38
Last edited by hbghlyj 2022-8-19 17:13
hbghlyj 发表于 2022-8-18 03:40
我发现会随机产生一些损坏的字符, 显示为 Unicode replacement character �(65533, U+FFFD)


加上gzip以后, 还是会随机出现损坏的字符
main-modified.png 5-Figure3-1.png

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-5 21:47
kuing将<base>去掉之后, 我在1#去掉了$\verb|.replace('<base href="https://kuing.cjhb.site/" />','<base href="http://cjhb.site:3001/" />')|$这一步

可以把tid列表给我一份吗, 就可以批量archive了, 谢谢

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-5 21:51
Cookie设为'__test=bf16be7e1cad023ea994c34ab6f950cb;'是预先测试好的
这个又不能用了, infinityfree的cookie-test page改变了擦擦

改成 _test=bf16be7e1cad023ea994c34ab6f950cb 可以用了
(原来是 双下划线, 现在是 单下划线, 而且现在不需要做那个aes数论密码计算了, 而是直接给cookie ! )

大家来测试一下proxy
cjhb.site:3001/forum.php?mod=viewthread&tid=9475

存档
web.archive.org/web/20220905141928/http://cjh … wthread&tid=9475

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-5 22:32
非常长的网页会导致Wayback Machine “超时未响应”的错误, 比如这帖(对应的proxy地址)
Screenshot 2022-09-02 at 02-02-12 mspace - MathML MDN.png

3153

Threads

7906

Posts

610K

Credits

Credits
64096
QQ

Show all posts

 Author| hbghlyj Posted 2022-9-5 22:38
非常长的网址会导致Wayback machine报错“URL syntax is not valid”
比如i.upmath.me/svg/\definecolor{blue}{HTML}{CCFF … };
\end{tikzpicture}

Screenshot 2022-09-02 at 02-02-12 mspace - MathML MDN.png
导致一些比较复杂的i.upmath.me的图片无法存档, 比如web.archive.org/web/20220905142221/http://cjh … wthread&tid=9543
Screenshot 2022-09-02 at 02-02-12 mspace - MathML MDN.png

Mobile version|Discuz Math Forum

2025-6-5 01:23 GMT+8

Powered by Discuz!

× Quick Reply To Top Edit