找回密码
 快速注册
搜索
查看: 112|回复: 8

[NodeJs] proxy

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-8-17 22:44 |阅读模式
本帖最后由 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);
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-17 23:26
本帖最后由 hbghlyj 于 2022-8-18 03:53 编辑 可以测试一下:
cjhb.site:3001
一个难点: Web Archive bot在有附件的帖子,不会自动下载附件,必须另外保存下载附件的URL. 话说, DiscuzX的“附件ID”是不变的吗? @kuing

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-18 10:40
本帖最后由 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再发送响应吗?

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-19 04:38
本帖最后由 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

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

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

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

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 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://cjhb.site:3001/forum.php?mod=viewthread&tid=9475

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

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

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-9-5 22:38
非常长的网址会导致Wayback machine报错“URL syntax is not valid”
比如i.upmath.me/svg/%5Cdefinecolor%7Bblue%7D%7BHTML%7D%7BCCFFFF%7D%0 ... end%7Btikzpicture%7D
Screenshot 2022-09-02 at 02-02-12 mspace - MathML MDN.png
导致一些比较复杂的i.upmath.me的图片无法存档, 比如web.archive.org/web/20220905142221/http://cjhb.site:3001/forum.php?mod=viewthread&tid=9543
Screenshot 2022-09-02 at 02-02-12 mspace - MathML MDN.png

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-9-8 18:02
@kuing
可以把tid列表给我一份吗, 就可以批量archive了, 现在没有aes了更方便

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 16:01

Powered by Discuz!

× 快速回复 返回顶部 返回列表