小编Bal*_*arr的帖子

如何限制从nodejs http模块上的其余服务器传入的块的大小?

我正在使用 Node.js 请求模块向 Node.js 请求休息服务器。如果传入数据大小超出允许的限制,我想取消流。这样做的目的是确保我的网络没有被锁定。

我的代码示例如下;

var http = require("http");

async function httpRequest({
  host,
  method,
  port,
  path
} = params, data) {
  if (method.toUpperCase() === "GET") {
    let query = "";
    data = JSON.parse(data);

    for (var key in data) {
      if (data.hasOwnProperty(key)) {
        let value = data[key];
        console.log(key + " -> " + value);
        query = query
          .concat("&")
          .concat(key)
          .concat("=")
          .concat(value);
      }
    }
    if (query) {
      query = "?".concat(query.substring(1));
    }
    path = encodeURI(path.concat(query));
    console.log("path : " + path);
  }
  var …
Run Code Online (Sandbox Code Playgroud)

javascript stream node.js node-https

0
推荐指数
1
解决办法
4273
查看次数

标签 统计

javascript ×1

node-https ×1

node.js ×1

stream ×1