MedusaRequest
Properties
abortedbooleanRequiredmessage.aborted property will be true if the request has been aborted.allowedPropertiesstring[]RequiredclosedbooleanRequiredtrue after 'close' has been emitted.completebooleanRequiredmessage.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.destroyedbooleanRequiredtrue after readable.destroy() has been called.errorsstring[]RequiredfilterableFieldsRecord<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); httpVersionstringRequired'1.1' or '1.0'. Also message.httpVersionMajor is the first integer andmessage.httpVersionMinor is the second.httpVersionMajornumberRequiredhttpVersionMinornumberRequiredincludesRecord<string, boolean>rawHeadersstring[]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); rawTrailersstring[]Required'end' event.readablebooleanRequiredtrue if it is safe to call readable.read(), which means the stream has not been destroyed or emitted 'error' or 'end'.readableAbortedbooleanRequired'end'.readableDidReadbooleanRequired'data' has been emitted.encoding of a given Readable stream. The encodingproperty can be set using the readable.setEncoding() method.readableEndedbooleanRequiredtrue when 'end' event is emitted.readableFlowingnull | booleanRequiredReadable stream as described in the Three states section.readableHighWaterMarknumberRequiredhighWaterMark passed when creating this Readable.readableLengthnumberRequiredhighWaterMark.readableObjectModebooleanRequiredobjectMode 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.statusCodenumber404.statusMessagestringOK 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.userObjectvalidatedBodyunknownRequiredMethods
[asyncDispose]
Calls readable.destroy() with an AbortError and returns a promise that fulfills when the stream is finished.
Returns
PromisePromise<void>RequiredSince
v20.4.0
[asyncIterator]
Returns
[captureRejectionSymbol]
Parameters
Returns
voidvoid_construct
Parameters
Returns
voidvoid_destroy
Parameters
Returns
voidvoid_read
Parameters
sizenumberRequiredReturns
voidvoidaddListener
**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
eventstring | 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
optionsPick<ArrayOptions, "signal">Returns
Since
v17.5.0
compose
Parameters
optionsobjectoptions.signalAbortSignalRequiredReturns
destroy
Calls destroy() on the socket that received the IncomingMessage. If erroris provided, an 'error' event is emitted on the socket and error is passed
as an argument to any listeners on the event.
Parameters
errorErrorReturns
Since
v0.3.0
drop
This method returns a new stream with the first limit chunks dropped from the start.
Parameters
limitnumberRequiredoptionsPick<ArrayOptions, "signal">Returns
Since
v17.5.0
emit
**emit**(event): boolean
Parameters
event"close"RequiredReturns
booleanboolean**emit**(event, chunk): boolean
Parameters
event"data"RequiredchunkanyRequiredReturns
booleanboolean**emit**(event): boolean
Parameters
event"end"RequiredReturns
booleanboolean**emit**(event, err): boolean
Parameters
event"error"RequiredReturns
booleanboolean**emit**(event): boolean
Parameters
event"pause"RequiredReturns
booleanboolean**emit**(event): boolean
Parameters
event"readable"RequiredReturns
booleanboolean**emit**(event): boolean
Parameters
event"resume"RequiredReturns
booleanboolean**emit**(event, ...args): boolean
Parameters
eventstring | symbolRequiredargsany[]RequiredReturns
booleanbooleaneventNames
Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbols.
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
awaited 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
optionsArrayOptionsReturns
PromisePromise<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 awaited.
Parameters
optionsArrayOptionsReturns
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
optionsArrayOptionsReturns
PromisePromise<undefined | T>Requiredundefined if no element was found.Since
v17.5.0
**find**(fn, options?): Promise<any>
Parameters
optionsArrayOptionsReturns
PromisePromise<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
optionsArrayOptionsReturns
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 awaited.
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
optionsArrayOptionsReturns
PromisePromise<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
numbernumberSince
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
booleanbooleanSince
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
optionsobjectoptions.destroyOnReturnbooleanfalse, 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
eventNamestring | symbolRequiredlistenerFunctionReturns
numbernumberSince
v3.2.0
listeners
Returns a copy of the array of listeners for the event named eventName.
Parameters
eventNamestring | 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 awaited before being passed to the result stream.
Parameters
optionsArrayOptions