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

whistle.https-handle

v1.0.18

Published

whistle plugin - Modify http request and response

Downloads

2

Readme

##自用,修改自whistle.http-handle, 去掉fixAndroid(alpine docker下出错), 更新版本号1.0.15->1.0.18

默认规则

* https-handle://

默认规则路径 js 文件为项目下的当前用户文件home文件夹下的 whistle.handle.rules/index.js,例如: windows:C:\Users\Administrator\whistle.http-handle.rules android:/sdcard/whistle.http-handle.rules/index.js

配置 whistle 规则 rules

匹配的域名 https-handle://自定义规则路径

wwww.baidu.com https-handle://E:\code\my\whistle.http-handle\index.js

流程图

流程图片

规则

  • reqConfig 真正请求时的数据配置

    • url 请求的 url
    • method 请求的方法
    • headers 头信息
    • query 查询字符串对象
    • bodyType body 的类型 formData|form|json|text
    • body 数据 string|object
  • reqConfig 返回客户端时的数据配置

    • statusCode 状态码
    • headers 头信息
    • body 数据 string|object|buffer object 时自动转为 json 字符串
  • next 传递给下一个请求的配置 传递false时为阻止请求或者响应

    • reqConfig
    • reqConfig

修改响应图片示例

const fs = require("fs");
const util = require("util");
const readFileAsync = util.promisify(fs.readFile);

module.exports = [
  {
    // 匹配的 url  **为多个通配字符,*为单个统配字符
    // 例如:https://www.baidu.com/action/**
    url: "**", //匹配所有请求url
    // 匹配的 method *表示所有
    method: "get",
    // 发送真正请求前 调用next()修改数据
    beforeSendRequest(reqConfig, next) {
      next(reqConfig);
    },
    // 返回响应给客户端前 调用next()修改数据
    beforeSendResponse(reqConfig, resConfig, next) {
      //判断响应的的类型是否是图片
      if (resConfig.headers["content-type"].includes("image")) {
        console.log("拦截图片响应...");
        // 读取本地文件
        const imagePath = "/storage/emulated/0/Pictures/cropedIMG_20230719_160944.jpg.png";
        readFileAsync(imagePath)
          .then(imageData => (resConfig.body = imageData)) // 将图片数据替换
          .catch(error => console.error(error))
          .finally(() => {
            next(resConfig); // 把响应给客户端
          });
      } else {
        next(resConfig); // 不是图片则不修改直接返回
      }
    }
  }
];