Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -13,7 +13,11 @@ const { isFormDataLike, formDataToStream } = require('./form-data')
const { EventEmitter } = require('node:events')
// request.connectin deprecation https://nodejs.org/api/http.html#http_request_connection
const FST_LIGHTMYREQUEST_DEP01 = createDeprecation({ name: 'FastifyDeprecationLightMyRequest', code: 'FST_LIGHTMYREQUEST_DEP01', message: 'You are accessing "request.connection", use "request.socket" instead.' })
const FST_LIGHTMYREQUEST_DEP01 = createDeprecation({
name: 'FastifyDeprecationLightMyRequest',
code: 'FST_LIGHTMYREQUEST_DEP01',
message: 'You are accessing "request.connection", use "request.socket" instead.'
})
/**
* Get hostname:port
@@ -103,6 +107,7 @@ function Request (options) {
this.headers = {}
this.rawHeaders = []
const headers = options.headers || {}
for (const field in headers) {
@@ -155,6 +160,7 @@ function Request (options) {
payloadResume = true
// we override the content-type
this.headers['content-type'] = stream.contentType
this.headers['transfer-encoding'] = 'chunked'
}
if (payload && typeof payload !== 'string' && !payloadResume && !Buffer.isBuffer(payload)) {
@@ -166,7 +172,7 @@ function Request (options) {
}
// Set the content-length for the corresponding payload if none set
if (payload && !payloadResume && !Object.prototype.hasOwnProperty.call(this.headers, 'content-length')) {
if (payload && !payloadResume && !Object.hasOwn(this.headers, 'content-length')) {
this.headers['content-length'] = (Buffer.isBuffer(payload) ? payload.length : Buffer.byteLength(payload)).toString()
}
@@ -178,50 +184,63 @@ function Request (options) {
this._lightMyRequest = {
payload,
isDone: false,
simulate: options.simulate || {}
simulate: options.simulate || {},
payloadAsStream: options.payloadAsStream,
signal: options.signal
}
const signal = options.signal
/* istanbul ignore if */
/* c8 ignore next 3 */
if (signal) {
addAbortSignal(signal, this)
}
{
const payload = this._lightMyRequest.payload
if (payload?._readableState) { // does quack like a modern stream
this._read = readStream
payload.on('error', (err) => {
this.destroy(err)
})
payload.on('end', () => {
this.push(null)
})
} else {
// Stream v1 are handled in index.js synchronously
this._read = readEverythingElse
}
}
return this
}
util.inherits(Request, Readable)
util.inherits(CustomRequest, Request)
Request.prototype.prepare = function (next) {
function readStream () {
const payload = this._lightMyRequest.payload
if (!payload || typeof payload.resume !== 'function') { // does not quack like a stream
return next()
let more = true
let pushed = false
let chunk
while (more && (chunk = payload.read())) {
pushed = true
more = this.push(chunk)
}
const chunks = []
payload.on('data', (chunk) => chunks.push(Buffer.from(chunk)))
payload.on('end', () => {
const payload = Buffer.concat(chunks)
this.headers['content-length'] = this.headers['content-length'] || ('' + payload.length)
this._lightMyRequest.payload = payload
return next()
})
// Force to resume the stream. Needed for Stream 1
payload.resume()
// We set up a recursive 'readable' event only if we didn't read anything.
// Otheriwse, the stream machinery will call _read() for us.
if (more && !pushed) {
this._lightMyRequest.payload.once('readable', this._read.bind(this))
}
}
Request.prototype._read = function (size) {
function readEverythingElse () {
setImmediate(() => {
if (this._lightMyRequest.isDone) {
// 'end' defaults to true
if (this._lightMyRequest.simulate.end !== false) {
this.push(null)
}
return
}
@@ -251,6 +270,9 @@ Request.prototype._read = function (size) {
})
}
util.inherits(Request, Readable)
util.inherits(CustomRequest, Request)
Request.prototype.destroy = function (error) {
if (this.destroyed || this._lightMyRequest.isDone) return
this.destroyed = true