简体   繁体   English

Node.js HTTP获取URL长度限制

[英]Node.js HTTP Get URL Length limitation

Is there a limit to the size when making HTTP GET requests in Node.js? 在Node.js中发出HTTP GET请求时是否有大小限制? And if so, how can I change this? 如果是这样,我该如何改变呢?

var url = "..." // very long, ~50'000 chars
http.get(url, function (res) {
    res.pipe(fs.createWriteStream("file.txt"));
});

Gives me this: 给我这个:

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>

Same thing using wget in PowerShell or Bash works perfectly fine. 在PowerShell或Bash中使用wget同样的功能完全正常。

$url = "..."
wget -outf file.txt $url

There is a built-in request size limit enforced by Node. Node强制执行内置请求大小限制。 Requested headers + URI should not be more than 80 kb. 请求的标头+ URI不应超过80 kb。

As it is defined in http_parser.h#L55 : 正如在http_parser.h#L55中定义的那样

/* Maximium header size allowed */
#define HTTP_MAX_HEADER_SIZE (80*1024)

Asuming that UTF-8 character can be between 1 and 4 bytes, the size of a string with 50 000 characters would be from 50 000 to 200 000 bytes, or from ~48kb to 195kb. 假设UTF-8字符可以在1到4个字节之间,则具有50 000个字符的字符串的大小将是从50 000到200 000字节,或从~48kb到195kb。

UPDATE UPDATE

In newer versions of NodeJS (v12.6.0+), the header request size limit is 8kb by default, and this also impacts the response header size. 在较新版本的NodeJS(v12.6.0 +)中,标头请求大小限制默认为8kb,这也会影响响应标头大小。 To use header sizes above 8KB, you can use the switch --max-http-header-size 65535 (or whatever size you need). 要使用大小超过8KB的标头,可以使用开关--max-http-header-size 65535 (或您需要的任何大小)。 This is described in-depth here . 这是深入描述在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM