MedusaRequest
Properties
aborted
booleanRequiredmessage.aborted
property will be true
if the request has been aborted.allowedProperties
string[]Requiredclosed
booleanRequiredtrue
after 'close'
has been emitted.complete
booleanRequiredmessage.complete
property will be true
if a complete HTTP message has been received and successfully parsed. This property is particularly useful as a means of determining if a client or server fully transmitted a message before a connection was terminated: js const req = http.request({ host: '127.0.0.1', port: 8080, method: 'POST', }, (res) => { res.resume(); res.on('end', () => { if (!res.complete) console.error( 'The connection was terminated while the message was still being sent'); }); });
message.socket
.destroyed
booleanRequiredtrue
after readable.destroy()
has been called.errors
string[]RequiredfilterableFields
Record<string, unknown>Requiredjs // Prints something like: // // { 'user-agent': 'curl/7.22.0', // host: '127.0.0.1:8000', // accept: '*' } console.log(request.headers);
Duplicates in raw headers are handled in the following ways, depending on the header name: * Duplicates of age
, authorization
, content-length
, content-type
,etag
, expires
, from
, host
, if-modified-since
, if-unmodified-since
,last-modified
, location
, max-forwards
, proxy-authorization
, referer
,retry-after
, server
, or user-agent
are discarded. To allow duplicate values of the headers listed above to be joined, use the option joinDuplicateHeaders
in request and createServer. See RFC 9110 Section 5.3 for more information. * set-cookie
is always an array. Duplicates are added to the array. * For duplicate cookie
headers, the values are joined together with ;
. * For all other headers, the values are joined together with ,
.message.headers
, but there is no join logic and the values are always arrays of strings, even for headers received just once. js // Prints something like: // // { 'user-agent': ['curl/7.22.0'], // host: ['127.0.0.1:8000'], // accept: ['*'] } console.log(request.headersDistinct);
httpVersion
stringRequired'1.1'
or '1.0'
. Also message.httpVersionMajor
is the first integer andmessage.httpVersionMinor
is the second.httpVersionMajor
numberRequiredhttpVersionMinor
numberRequiredincludes
Record<string, boolean>rawHeaders
string[]Requiredjs // Prints something like: // // [ 'user-agent', // 'this is invalid because there can be only one', // 'User-Agent', // 'curl/7.22.0', // 'Host', // '127.0.0.1:8000', // 'ACCEPT', // '*' ] console.log(request.rawHeaders);
rawTrailers
string[]Required'end'
event.readable
booleanRequiredtrue
if it is safe to call readable.read()
, which means the stream has not been destroyed or emitted 'error'
or 'end'
.readableAborted
booleanRequired'end'
.readableDidRead
booleanRequired'data'
has been emitted.encoding
of a given Readable
stream. The encoding
property can be set using the readable.setEncoding()
method.readableEnded
booleanRequiredtrue
when 'end'
event is emitted.readableFlowing
null | booleanRequiredReadable
stream as described in the Three states
section.readableHighWaterMark
numberRequiredhighWaterMark
passed when creating this Readable
.readableLength
numberRequiredhighWaterMark
.readableObjectMode
booleanRequiredobjectMode
of a given Readable
stream.net.Socket
object associated with the connection. With HTTPS support, use request.socket.getPeerCertificate()
to obtain the client's authentication details. This property is guaranteed to be an instance of the net.Socket
class, a subclass of stream.Duplex
, unless the user specified a socket type other than net.Socket
or internally nulled.statusCode
number404
.statusMessage
stringOK
or Internal Server Error
.'end'
event.message.trailers
, but there is no join logic and the values are always arrays of strings, even for headers received just once. Only populated at the 'end'
event.user
ObjectvalidatedBody
unknownRequiredMethods
[asyncDispose]
Calls readable.destroy()
with an AbortError
and returns a promise that fulfills when the stream is finished.
Returns
Promise
Promise<void>RequiredSince
v20.4.0
[asyncIterator]
Returns
[captureRejectionSymbol]
Parameters
Returns
void
void_construct
Parameters
Returns
void
void_destroy
Parameters
Returns
void
void_read
Parameters
size
numberRequiredReturns
void
voidaddListener
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Event emitter The defined events on documents including:
- close
- data
- end
- error
- pause
- readable
- resume
Parameters
event
"close"Requiredlistener
() => voidRequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
"data"Requiredlistener
(chunk: any) => voidRequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
"end"Requiredlistener
() => voidRequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
"error"RequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
"pause"Requiredlistener
() => voidRequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
"readable"Requiredlistener
() => voidRequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
"resume"Requiredlistener
() => voidRequiredReturns
**addListener**(event, listener): [MedusaRequest](/references/js-client/internal/interfaces/internal.internal.MedusaRequest)
Parameters
event
string | symbolRequiredlistener
(...args: any[]) => voidRequiredReturns
asIndexedPairs
This method returns a new stream with chunks of the underlying stream paired with a counter
in the form [index, chunk]
. The first index value is 0
and it increases by 1 for each chunk produced.
Parameters
options
Pick<ArrayOptions, "signal">Returns
Since
v17.5.0
compose
Parameters
options
objectoptions.signal
AbortSignalRequiredReturns
destroy
Calls destroy()
on the socket that received the IncomingMessage
. If error
is provided, an 'error'
event is emitted on the socket and error
is passed
as an argument to any listeners on the event.
Parameters
error
ErrorReturns
Since
v0.3.0
drop
This method returns a new stream with the first limit chunks dropped from the start.
Parameters
limit
numberRequiredoptions
Pick<ArrayOptions, "signal">Returns
Since
v17.5.0
emit
**emit**(event): boolean
Parameters
event
"close"RequiredReturns
boolean
boolean**emit**(event, chunk): boolean
Parameters
event
"data"Requiredchunk
anyRequiredReturns
boolean
boolean**emit**(event): boolean
Parameters
event
"end"RequiredReturns
boolean
boolean**emit**(event, err): boolean
Parameters
event
"error"RequiredReturns
boolean
boolean**emit**(event): boolean
Parameters
event
"pause"RequiredReturns
boolean
boolean**emit**(event): boolean
Parameters
event
"readable"RequiredReturns
boolean
boolean**emit**(event): boolean
Parameters
event
"resume"RequiredReturns
boolean
boolean**emit**(event, ...args): boolean
Parameters
event
string | symbolRequiredargs
any[]RequiredReturns
boolean
booleaneventNames
Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
Returns
(string \| symbol)[]
(string | symbol)[]RequiredSince
v6.0.0
every
This method is similar to Array.prototype.every
and calls fn on each chunk in the stream
to check if all awaited return values are truthy value for fn. Once an fn call on a chunk
await
ed return value is falsy, the stream is destroyed and the promise is fulfilled with false
.
If all of the fn calls on the chunks return a truthy value, the promise is fulfilled with true
.
Parameters
options
ArrayOptionsReturns
Promise
Promise<boolean>Requiredtrue
if fn returned a truthy value for every one of the chunks.Since
v17.5.0
filter
This method allows filtering the stream. For each chunk in the stream the fn function will be called
and if it returns a truthy value, the chunk will be passed to the result stream.
If the fn function returns a promise - that promise will be await
ed.
Parameters
options
ArrayOptionsReturns
Since
v17.4.0, v16.14.0
find
**find**<TypeParameter T>(fn, options?): Promise<undefined \| T>
This method is similar to Array.prototype.find
and calls fn on each chunk in the stream
to find a chunk with a truthy value for fn. Once an fn call's awaited return value is truthy,
the stream is destroyed and the promise is fulfilled with value for which fn returned a truthy value.
If all of the fn calls on the chunks return a falsy value, the promise is fulfilled with undefined
.
Parameters
options
ArrayOptionsReturns
Promise
Promise<undefined | T>Requiredundefined
if no element was found.Since
v17.5.0
**find**(fn, options?): Promise<any>
Parameters
options
ArrayOptionsReturns
Promise
Promise<any>RequiredflatMap
This method returns a new stream by applying the given callback to each chunk of the stream and then flattening the result.
It is possible to return a stream or another iterable or async iterable from fn and the result streams will be merged (flattened) into the returned stream.
Parameters
options
ArrayOptionsReturns
Since
v17.5.0
forEach
This method allows iterating a stream. For each chunk in the stream the fn function will be called.
If the fn function returns a promise - that promise will be await
ed.
This method is different from for await...of
loops in that it can optionally process chunks concurrently.
In addition, a forEach
iteration can only be stopped by having passed a signal
option
and aborting the related AbortController while for await...of
can be stopped with break
or return
.
In either case the stream will be destroyed.
This method is different from listening to the 'data'
event in that it uses the readable
event
in the underlying machinary and can limit the number of concurrent fn calls.
Parameters
options
ArrayOptionsReturns
Promise
Promise<void>RequiredSince
v17.5.0
getMaxListeners
Returns the current max listener value for the EventEmitter
which is either
set by emitter.setMaxListeners(n)
or defaults to defaultMaxListeners.
Returns
number
numberSince
v1.0.0
isPaused
The readable.isPaused()
method returns the current operating state of theReadable
. This is used primarily by the mechanism that underlies thereadable.pipe()
method. In most
typical cases, there will be no reason to
use this method directly.
Returns
boolean
booleanSince
v0.11.14
iterator
The iterator created by this method gives users the option to cancel the destruction
of the stream if the for await...of
loop is exited by return
, break
, or throw
,
or if the iterator should destroy the stream if the stream emitted an error during iteration.
Parameters
options
objectoptions.destroyOnReturn
booleanfalse
, calling return
on the async iterator, or exiting a for await...of
iteration using a break
, return
, or throw
will not destroy the stream. Default: true
.Returns
Since
v16.3.0
listenerCount
Returns the number of listeners listening for the event named eventName
.
If listener
is provided, it will return how many times the listener is found
in the list of the listeners of the event.
Parameters
eventName
string | symbolRequiredlistener
FunctionReturns
number
numberSince
v3.2.0
listeners
Returns a copy of the array of listeners for the event named eventName
.
Parameters
eventName
string | symbolRequiredReturns
Function[]
Function[]RequiredSince
v0.1.26
map
This method allows mapping over the stream. The fn function will be called for every chunk in the stream.
If the fn function returns a promise - that promise will be await
ed before being passed to the result stream.
Parameters
options
ArrayOptions