[http.IncomingMessage] `req.toWeb()`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the existing http.createServer/IncomingMessage path and the stream.Readable.toWeb() API named in the issue first. Define and verify a conversion to a web Request that preserves the proposed body methods, headers, URL, and abort signal behavior; done means the requested req.toWeb() interface works for these cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100