npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

network-traffic-recorder

v1.0.18

Published

凭借 HTTP/HTTPS 正向代理,录制与回放 HTTP 请求。

Downloads

3

Readme

network-traffic-recorder

网络数据录制器

功能

通过一个网络中间代理层,拦截、缓存与分析HTTP往返数据流。并且,对后继的前端HTTP请求,回放 被缓存的真实服务器响应数据。 最终,实现网络应用程序的

  1. 场景录制
  2. Bug重现

原理

  1. 一个 HTTP + HTTPS 的·正向代理服务·被构建。它是整个功能实现的核心。
  2. 在 HTTP(S) 请求被正向代理过程中,拦截、缓存与分析每一个HTTP请求的往返数据。
  3. HTTP/304化。为了避免缓存无意义的HTTP/304回复指令。·正向代理服务·在请求接力转发过程中,强制地 抹去了if-modifiedif-matchHTTP缓存指令头。
  4. 缓存HTTP往返数据流入本地文件,以完成数据持久化、共享/回放。

妥协

  1. 考虑到被缓存分析的数据量,仅只 缓存、分析与回放 mimeapplication/jsonHTTP往返数据流。
  2. HTTPS往返数据流仅只被透传,并没有被缓存与分析。
  3. HTTP往返数据流被缓存为base64字符串。而不是被ungzip之后的明文结果。在做数据分析时,才独立地去做ungzip处理。此外,这样也有利于今后缓存非文本类的数据内容。

回放缓存数据的条件

  1. HTTP Method 相同
  2. Server Path / pathname 相同
  3. URL查询字符串 中的参数 都 相同,不论次序。
  4. 请求头中 content-type 相同
  5. application/x-www-form-urlencoded 表单数据中的 每一个键值对 相同,不论次序。
  6. application/octet-stream(即,文件/图片上传),要求前后两次上传文件/图片的内容完全相同。

安装

npm i network-traffic-recorder -g

运行

nodejs 版本最低要求

  • nodejs v8.9.1+

启动作为【正向代理】服务器

监听默认端口【6891】

network-traffic-recorder-single.cmd

指定监听端口

network-traffic-recorder-single.cmd -p 7543

启动作为【独立HTTP SERVER】(不是,正向代理)

需要明确地指定被代理的目标服务器的·目标主机域名·与·目标端口号·。 独立服务自身监听端口号的命令行参数同【正向代理】工作模式。即,-p参数。

network-traffic-recorder-single.cmd --target-host=${目标主机域名} --target-port=${目标端口号}

查看所有命令行参数,请执行指令 network-traffic-recorder-single.cmd --help

于是,就会获取如下帮助提示

usage: index.js [-h] [-v] [-p PORT] [-d DIRECTORY]

基于HTTP(S)正向代理的网络数据录制器

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program\'s version number and exit.
  -ai, --auto-ip        是否自动绑定当前主机IP
  -p PORT, --port PORT  监听端口号。 (默认值: 6891)
  -d DIRECTORY, --directory DIRECTORY
                        录制结果保存目录。(默认目录: ${current-working-folder}/tapes)
  -c {all,json}, --cache {all,json}
                        录制请求响应数据流的类型:【全部】all,【JSON】json。(默认类型:
                        json,仅只录制"content-type": "application/json"的网络交通)
  -th TARGETHOST, --target-host TARGETHOST
                        当以独立·HTTP SERVER·(而不是,正向代理)运行时,将要被代理的【主机域名】
  -tp TARGETPORT, --target-port TARGETPORT
                        当以独立·HTTP SERVER·(而不是,正向代理)运行时,将要被代理的【主机端口号】。(默认值: 80)

观察输出日志第一行

init forward proxy listening on 192.168.50.235:6891 +0ms

复制出·正向代理服务·的·主机名/域名·与·端口号·。在这里,它们分别是192.168.50.2356891。 下面在修改·手机·或·桌面浏览器·网络配置时,需要录入这两个值。

设置 手机网络代理 指向 此正向代理服务

【设备】 -> 【WLAN】 -> 长按WiFi配置项 -> 【修改网络】 -> 【高级选项】 -> 【代理】 -> 选择【手动】 -> 输入

  1. 代理服务器主机名192.168.50.235
  2. 代理服务器端口号6891

设置 桌面浏览器网络代理 指向 此正向代理服务

【选项】 -> 【常用】 -> 【网络代理】 -> 【手动代理配置】 -> 【HTTP代理】 -> 输入

  1. 代理服务器主机名192.168.50.235
  2. 代理服务器端口号6891

数据缓存文件

记录了HTTP往返数据流的缓存文件位于:执行命令所在目录下的tapes/子目录下的一组本地json文件内。其中,每一个json文件的文件名格式为:http_域名_端口号.json

未来改进方向

并发多进程

跨进程写文件·同步锁·要求:所有的slaver进程将文件内容使用postMessage发送给cluster进程进行统一写文件操作。cluster进程也需要根据从slaver进程传递来的文件内容的时间戳对所有文件内容片段进行排序。然后,cluster进程再写文件。

拆包HTTPS往返数据流