[http.IncomingMessage] `req.toWeb()`
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
What is the problem this feature will solve?
Reading the body out of the http.IncomingMessage is troublesome without any 3th party package...
Request on the other hand has features such as text, blob, json, arrayBuffer, formData bytes, and body for parsing it.
What is the feature you are proposing to solve the problem?
It would be a convenient to have something like a req.toWeb() utility added onto the simple http server 🚀
something like the stream.Readable.toWeb() but for the http.IncomingRequest to web Request
import http from 'node:http'
const app = http.createServer(async (req, res) => {
const request = req.toWeb()
await request.blob()
await request.arrayBuffer()
await request.bytes()
await request.formData()
await request.json()
await request.body.pipeTo(dest)
request.headers.has('content-length') // now getting the benefit of case insensitive.
// full url (populated with host from request headers and http(s) based on using http or https)
request.url
// a abort signal that aborts when user cancel the request
// can be useful for aborting other pending database queries
request.signal
})
What alternatives have you considered?
currently doing some simplier variant like this one:
const app = http.createServer((r, res) => {
const req = new Request(r.url, {
headers: r.headers,
method: r.method,
body: r
})
})
having this req.toWeb() built in would be very handy
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读现有的 http.createServer/IncomingMessage 路径,以及 issue 中提到的 stream.Readable.toWeb() API。定义并验证到 web Request 的转换,确保保留所提议的 body 方法、headers、URL 和 abort signal 行为;当所请求的 req.toWeb() 接口能够处理这些情况时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 50/100