简体   繁体   English

HTTP 在 Docker 容器中运行时,Nodejs 中的解析错误

[英]HTTP Parse Error in Nodejs when running in a Docker Container

I have a Nestjs Application which I try to run in a docker container.我有一个 Nestjs 应用程序,我尝试在 docker 容器中运行。 It all worked fine just until recently where I get the error Parse Error: Missing expected CR after header value .直到最近我收到错误Parse Error: Missing expected CR after header value ,这一切都运行良好。 I'm trying to make a http GET Request to a webserver of an IoT device.我正在尝试向物联网设备的网络服务器发出 http GET 请求。 Furthermore this error occurs only when I run the server-app inside a docker container.此外,仅当我在 docker 容器内运行服务器应用程序时才会发生此错误。 When I run it locally on a windows or macos machine everything works fine.当我在 windows 或 macos 机器上本地运行它时,一切正常。

I tried using different versions of nodejs in docker.我尝试在 docker 中使用不同版本的 nodejs。 14, 16 and 18. This error always comes up, independent of which version I use. 14、16和18。这个错误总是出现,与我使用的版本无关。 I have no idea how I could debug this error, since it only occurs when I serve the app inside a docker container.我不知道如何调试此错误,因为它仅在我在 docker 容器内提供应用程序时发生。

This is my dockerfile:这是我的 dockerfile:

FROM node:slim
RUN mkdir -p /app
WORKDIR /app
COPY src .
COPY package.json .
RUN apt update && apt install python3 make g++ -y
RUN npm install --force
EXPOSE 3000
CMD ["npm", "run", "start:dev"]

According to this issue , this was recently implemented in Node v14.20.0, v16.16.0 and v18.5.0.根据这个问题,这是最近在 Node v14.20.0、v16.16.0 和 v18.5.0 中实现的。 Apparently it fixes a vulnerability in the HTTP parser of earlier versions.显然它修复了早期版本的 HTTP 解析器中的一个漏洞。

Comments below the issue suggest various workarounds if it's not possible to fix the client, the easiest of which seems to be to set the insecureHTTPParser flag to true when creating the HTTP server.如果无法修复客户端,问题下方的评论建议了各种解决方法,其中最简单的方法似乎是在创建 HTTP 服务器时将insecureHTTPParser标志设置为true

Alternatively, revert to an older minor version of each of the Node.js versions mentioned above.或者,恢复到上述每个 Node.js 版本的旧次要版本。

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

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