WebSocketOperationContext
Class: WebSocketOperationContext
Defined in: packages/core/src/contexts/websocketcontext.ts:19
The context of a bidirectional operation served over a WebSocket: the upgrade request's headers and session, each streamed chunk sent as one JSON text message.
Extends
Constructors
Constructor
new WebSocketOperationContext(
httpContext,socket,session?):WebSocketOperationContext
Defined in: packages/core/src/contexts/websocketcontext.ts:27
Parameters
httpContext
the upgrade request
socket
WebSocket
the accepted socket
session?
the session already loaded for the upgrade request, if any
Returns
WebSocketOperationContext
Overrides
StreamingOperationContext.constructor
Properties
_body
protected_body:string
Defined in: packages/core/src/contexts/operationcontext.ts:49
Output
Inherited from
StreamingOperationContext._body
_cookie
_cookie:
Map<string,Cookie>
Defined in: packages/core/src/contexts/webcontext.ts:38
Cookies to send back
Inherited from
StreamingOperationContext._cookie
_ended
_ended:
Promise<any> =undefined
Defined in: packages/core/src/contexts/webcontext.ts:45
Inherited from
StreamingOperationContext._ended
_outputHeaders
protected_outputHeaders:OutgoingHttpHeaders
Defined in: packages/core/src/contexts/webcontext.ts:29
Contains the response headers
Inherited from
StreamingOperationContext._outputHeaders
_promises
_promises:
Promise<any>[]
Defined in: packages/core/src/contexts/icontext.ts:33
Contain all registered promises to this context
Inherited from
StreamingOperationContext._promises
_route
_route:
any
Defined in: packages/core/src/contexts/webcontext.ts:43
Inherited from
StreamingOperationContext._route
_sanitized
protected_sanitized:any
Defined in: packages/core/src/contexts/operationcontext.ts:44
Contain the sanitized request body if computed
Inherited from
StreamingOperationContext._sanitized
_sessionSaved
protected_sessionSaved:boolean=false
Defined in: packages/core/src/contexts/webcontext.ts:49
Whether the session was already saved
Inherited from
StreamingOperationContext._sessionSaved
_stream
_stream:
Writable
Defined in: packages/core/src/contexts/operationcontext.ts:85
Output stream
Inherited from
StreamingOperationContext._stream
caches
caches:
any
Defined in: packages/core/src/contexts/icontext.ts:19
Get the caches linked to the context
Inherited from
StreamingOperationContext.caches
extensions
protectedextensions:object
Defined in: packages/core/src/contexts/icontext.ts:23
Allow extensions
Index Signature
[key: string]: any
Inherited from
StreamingOperationContext.extensions
flushed
protectedflushed:boolean=false
Defined in: packages/core/src/contexts/icontext.ts:37
If the headers were flushed
Inherited from
StreamingOperationContext.flushed
headers
headers:
Map<string,string>
Defined in: packages/core/src/contexts/webcontext.ts:42
Inherited from
StreamingOperationContext.headers
headersFlushed
protectedheadersFlushed:boolean
Defined in: packages/core/src/contexts/webcontext.ts:54
If headers were flushed
Inherited from
StreamingOperationContext.headersFlushed
parameters
parameters:
any
Defined in: packages/core/src/contexts/operationcontext.ts:56
Inherited from
StreamingOperationContext.parameters
session
protectedsession:Session
Defined in: packages/core/src/contexts/operationcontext.ts:40
Session
Inherited from
StreamingOperationContext.session
statusCode
statusCode:
number
Defined in: packages/core/src/contexts/webcontext.ts:34
Current status code
Inherited from
StreamingOperationContext.statusCode
Accessors
connectionEnded
Get Signature
get
protectedconnectionEnded():boolean
Defined in: packages/core/src/contexts/websocketcontext.ts:48
The socket is closing or closed
Returns
boolean
Overrides
StreamingOperationContext.connectionEnded
isCancelled
Get Signature
get isCancelled():
boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:36
Returns
boolean
whether the client went away
Inherited from
StreamingOperationContext.isCancelled
Methods
addAsyncRequest()
addAsyncRequest(
promise):void
Defined in: packages/core/src/contexts/operationcontext.ts:136
Register a promise with the context
Parameters
promise
any
the promise to add
Returns
void
Inherited from
StreamingOperationContext.addAsyncRequest
assertAlive()
protectedassertAlive():void
Defined in: packages/core/src/contexts/streamingcontext.ts:78
Returns
void
Throws
OperationCancelledError when the client went away or the connection is over
Inherited from
StreamingOperationContext.assertAlive
cancel()
cancel():
void
Defined in: packages/core/src/contexts/streamingcontext.ts:41
The client went away: the next write or drain throws.
Returns
void
Inherited from
StreamingOperationContext.cancel
clearInput()
clearInput():
void
Defined in: packages/core/src/contexts/operationcontext.ts:161
Remove the input
Returns
void
Inherited from
StreamingOperationContext.clearInput
cookie()
cookie(
param,value,options?):void
Defined in: packages/core/src/contexts/webcontext.ts:185
For compatibility reason
Parameters
param
any
the parameter name
value
any
the value to set
options?
any = undefined
the options
Returns
void
Inherited from
StreamingOperationContext.cookie
createStream()
createStream():
void
Defined in: packages/core/src/contexts/operationcontext.ts:286
Create a buffer stream
Returns
void
Inherited from
StreamingOperationContext.createStream
drained()
drained():
Promise<void>
Defined in: packages/core/src/contexts/streamingcontext.ts:101
Wait for the transport to take more output, without leaving listeners behind
Returns
Promise<void>
Throws
OperationCancelledError when the client went away, the connection is over or the transport failed
Inherited from
StreamingOperationContext.drained
end()
end():
Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:277
Flush the request
Returns
Promise<any>
the result
Emits
'finish' event
Throws
Error if the request was already ended
Inherited from
flushHeaders()
flushHeaders():
Promise<void>
Defined in: packages/core/src/contexts/webcontext.ts:406
Returns
Promise<void>
Inherited from
StreamingOperationContext.flushHeaders
getCurrentUser()
getCurrentUser<
K>(refresh?):Promise<K>
Defined in: packages/core/src/contexts/operationcontext.ts:351
Get the current user from session
Type Parameters
K
K extends IUser
Parameters
refresh?
boolean = false
whether to refresh
Returns
Promise<K>
the result
Inherited from
StreamingOperationContext.getCurrentUser
getCurrentUserId()
getCurrentUserId():
string
Defined in: packages/core/src/contexts/operationcontext.ts:371
Get the current user id from session
A session waiting for its second factor (mfa: "pending") is not logged: it has no current user. Code that needs
the pending user reads getSession().userId.
Returns
string
the result
Inherited from
StreamingOperationContext.getCurrentUserId
getExtension()
getExtension<
K>(name):K
Defined in: packages/core/src/contexts/operationcontext.ts:91
Get an extension of the context
Type Parameters
K
K = any
Parameters
name
string
of the extension
Returns
K
extension object
Inherited from
StreamingOperationContext.getExtension
getHttpContext()
getHttpContext():
HttpContext
Defined in: packages/core/src/contexts/webcontext.ts:71
Get current http context
Returns
the result
Inherited from
StreamingOperationContext.getHttpContext
getInput()
getInput(
sanitizedOptions?):Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:97
A multipart body (file upload) is never JSON: return the default value
instead of letting the parent try to JSON.parse it and log an error.
The raw body stays available to getRawInput()/getRawStream().
Parameters
sanitizedOptions?
IOptions & object
Returns
Promise<any>
Inherited from
StreamingOperationContext.getInput
getLocale()
getLocale():
string
Defined in: packages/core/src/contexts/webcontext.ts:359
Get the request locale if found
Returns
string
the result
Inherited from
StreamingOperationContext.getLocale
getOutput()
getOutput():
string
Defined in: packages/core/src/contexts/operationcontext.ts:144
Get output as string, if a OutputStream is provided it will returned null
Returns
string
the result string
Inherited from
StreamingOperationContext.getOutput
getOutputStream()
getOutputStream():
Promise<Writable>
Defined in: packages/core/src/contexts/operationcontext.ts:251
Get the HTTP stream to output raw data
Returns
Promise<Writable>
the result
Inherited from
StreamingOperationContext.getOutputStream
getParameters()
getParameters():
any
Defined in: packages/core/src/contexts/operationcontext.ts:109
Get the parameters
Returns
any
the result
Inherited from
StreamingOperationContext.getParameters
getRawInput()
getRawInput(
limit?,timeout?):Promise<Buffer<ArrayBufferLike>>
Defined in: packages/core/src/contexts/webcontext.ts:107
Parameters
limit?
number = ...
timeout?
number = 60000
Returns
Promise<Buffer<ArrayBufferLike>>
Inherited from
StreamingOperationContext.getRawInput
getRawInputAsString()
getRawInputAsString(
limit?,timeout?,encoding?):Promise<string>
Defined in: packages/core/src/contexts/webcontext.ts:83
Get the raw input as string
Any WHATWG Encoding Standard label is accepted as encoding (utf-8, iso-8859-1, shift_jis, ...) If no encoding is given, the charset of the Content-Type header is used, falling back to UTF-8
Parameters
limit?
number = ...
timeout?
number = 60000
encoding?
string
Returns
Promise<string>
Inherited from
StreamingOperationContext.getRawInputAsString
getRawStream()
getRawStream():
Readable
Defined in: packages/core/src/contexts/webcontext.ts:114
Returns
Readable
Inherited from
StreamingOperationContext.getRawStream
getRequest()
getRequest():
IncomingMessage
Defined in: packages/core/src/contexts/webcontext.ts:333
Retrieve a http.IncomingMessage valid from Context
Need more testing
Returns
IncomingMessage
the result
Inherited from
StreamingOperationContext.getRequest
getRequestBody()
getRequestBody(
sanitizedOptions?):Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:307
Alias to keep compatibility with WebContext
Parameters
sanitizedOptions?
any = ...
the sanitized options
Returns
Promise<any>
the result
Inherited from
StreamingOperationContext.getRequestBody
getResponseBody()
getResponseBody():
any
Defined in: packages/core/src/contexts/webcontext.ts:320
Get request body
Returns
any
the result
Inherited from
StreamingOperationContext.getResponseBody
getResponseCode()
getResponseCode():
number
Defined in: packages/core/src/contexts/webcontext.ts:168
Returns
number
the result
Inherited from
StreamingOperationContext.getResponseCode
getResponseCookies()
getResponseCookies():
Map<string,Cookie>
Defined in: packages/core/src/contexts/webcontext.ts:197
Get all cookies set on the response
Returns
Map<string, Cookie>
the result map
Inherited from
StreamingOperationContext.getResponseCookies
getResponseHeaders()
getResponseHeaders():
OutgoingHttpHeaders
Defined in: packages/core/src/contexts/webcontext.ts:399
Return the merged response headers — defaults set by the constructor
(_outputHeaders) overlaid with any headers added via setHeader() /
writeHead(). Same merge order as flushHeaders writes to the wire,
so callers (logging, capture, transports) see exactly what the client
will receive.
Returns
OutgoingHttpHeaders
the merged response headers
Inherited from
StreamingOperationContext.getResponseHeaders
getResponseSize()
getResponseSize():
number
Defined in: packages/core/src/contexts/webcontext.ts:248
Return the response size
Returns
number
the result
Inherited from
StreamingOperationContext.getResponseSize
getSession()
getSession<
K>():K
Defined in: packages/core/src/contexts/operationcontext.ts:260
Get linked session
Type Parameters
K
K = Session
Returns
K
the result
Inherited from
StreamingOperationContext.getSession
getSetCookieHeaders()
getSetCookieHeaders():
string[]
Defined in: packages/core/src/contexts/webcontext.ts:205
The Set-Cookie header values of the response, one per cookie
Returns
string[]
the serialized cookies
Inherited from
StreamingOperationContext.getSetCookieHeaders
hasFlushedHeaders()
hasFlushedHeaders():
boolean
Defined in: packages/core/src/contexts/webcontext.ts:373
Return true if Headers got flushed already
Returns
boolean
the result
Inherited from
StreamingOperationContext.hasFlushedHeaders
init()
init():
Promise<WebSocketOperationContext>
Defined in: packages/core/src/contexts/websocketcontext.ts:40
The session of an authorized upgrade is reused, not loaded twice
Returns
Promise<WebSocketOperationContext>
Overrides
StreamingOperationContext.init
isEnded()
isEnded():
Promise<any>
Defined in: packages/core/src/contexts/webcontext.ts:213
Whether the response has been ended
Returns
Promise<any>
the result
Inherited from
StreamingOperationContext.isEnded
isGlobalContext()
isGlobalContext():
boolean
Defined in: packages/core/src/contexts/icontext.ts:43
Whether this is the global (non-request-scoped) context
Returns
boolean
true if the condition is met
Inherited from
StreamingOperationContext.isGlobalContext
json()
json(
obj):this
Defined in: packages/core/src/contexts/webcontext.ts:239
Express response allow answer to be sent this way
Parameters
obj
any
the target object
Returns
this
this for chaining
Inherited from
StreamingOperationContext.json
newSession()
newSession():
Session
Defined in: packages/core/src/contexts/operationcontext.ts:268
Create and assign a new empty session
Returns
the result
Inherited from
StreamingOperationContext.newSession
parameter()
parameter(
name,defaultValue?):any
Defined in: packages/core/src/contexts/operationcontext.ts:101
Get one parameter
Parameters
name
string
the name to use
defaultValue?
any = undefined
the default value
Returns
any
the result
Inherited from
StreamingOperationContext.parameter
pipeline()
pipeline(
stream1, ...streams):Promise<void>
Defined in: packages/core/src/contexts/icontext.ts:149
Pipeline streams into the output stream
Parameters
stream1
ReadableStream
the first stream
streams
...(ReadWriteStream | PipelineOptions)[]
additional streams
Returns
Promise<void>
See
https://nodejs.org/api/stream.html#streampipelinestreams-options
Inherited from
StreamingOperationContext.pipeline
redirect()
redirect(
url):void
Defined in: packages/core/src/contexts/webcontext.ts:176
Redirect to another url
Parameters
url
string
the URL
Returns
void
Inherited from
StreamingOperationContext.redirect
registerPromise()
registerPromise(
promise):void
Defined in: packages/core/src/contexts/icontext.ts:56
Register a promise with the context
Parameters
promise
any
the promise to add
Returns
void
Inherited from
StreamingOperationContext.registerPromise
reinit()
reinit():
void
Defined in: packages/core/src/contexts/operationcontext.ts:276
Remove sanitized body
Returns
void
Inherited from
StreamingOperationContext.reinit
resetResponse()
resetResponse():
void
Defined in: packages/core/src/contexts/webcontext.ts:121
Remove everything that was about to be sent
Returns
void
Inherited from
StreamingOperationContext.resetResponse
saveSession()
saveSession():
Promise<void>
Defined in: packages/core/src/contexts/webcontext.ts:257
Save the session through the SessionManager, once
The SessionManager writes the session cookie: call it before the headers are flushed
Returns
Promise<void>
Inherited from
StreamingOperationContext.saveSession
sendChunk()
protectedsendChunk(chunk):boolean
Defined in: packages/core/src/contexts/websocketcontext.ts:56
One JSON text message per chunk
Parameters
chunk
any
Returns
boolean
Overrides
StreamingOperationContext.sendChunk
setExtension()
setExtension(
name,extension):this
Defined in: packages/core/src/contexts/operationcontext.ts:127
Parameters
name
string
to add
extension
any
object to store
Returns
this
this for chaining
Inherited from
StreamingOperationContext.setExtension
setFlushedHeaders()
setFlushedHeaders(
status?):void
Defined in: packages/core/src/contexts/webcontext.ts:381
Set flushed header status
Parameters
status?
boolean = true
the HTTP status code
Returns
void
Inherited from
StreamingOperationContext.setFlushedHeaders
setHeader()
setHeader(
name,value):void
Defined in: packages/core/src/contexts/icontext.ts:104
Set a header in the response
Parameters
name
string
the name to use
value
string | number | string[]
the value to set
Returns
void
Inherited from
StreamingOperationContext.setHeader
setHttpContext()
setHttpContext(
httpContext):void
Defined in: packages/core/src/contexts/webcontext.ts:62
Set current http context
Parameters
httpContext
current http context
Returns
void
Inherited from
StreamingOperationContext.setHttpContext
setParameters()
setParameters(
params):void
Defined in: packages/core/src/contexts/operationcontext.ts:117
Set the parameters
Parameters
params
any
the service parameters
Returns
void
Inherited from
StreamingOperationContext.setParameters
setSession()
setSession(
session):void
Defined in: packages/core/src/contexts/operationcontext.ts:78
Set the session
Parameters
session
the session object
Returns
void
Inherited from
StreamingOperationContext.setSession
status()
status(
code):this
Defined in: packages/core/src/contexts/webcontext.ts:228
Express response allow statusCode to be defined this way
Parameters
code
number
to return
Returns
this
this for chaining
Inherited from
StreamingOperationContext.status
waitForDrain()
protectedwaitForDrain(signal):Promise<void>
Defined in: packages/core/src/contexts/websocketcontext.ts:70
Wait for the last message to be flushed, or the socket to close
Parameters
signal
AbortSignal
Returns
Promise<void>
Overrides
StreamingOperationContext.waitForDrain
write()
write(
output,encoding?,cb?):boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:90
Streamed chunks go out immediately; a non-streamed result is buffered
Parameters
output
any
encoding?
string
cb?
(error) => void
Returns
boolean
Throws
OperationCancelledError when streaming and the client went away or the connection is over
Inherited from
StreamingOperationContext.write
writeHead()
writeHead(
statusCode,headers?):this
Defined in: packages/core/src/contexts/webcontext.ts:154
Write the http return code and some headers Those headers are not flushed yet so can still be overwritten
Parameters
statusCode
number
to return to the client
headers?
OutgoingHttpHeaders = undefined
to add to the response
Returns
this
this for chaining
Inherited from
StreamingOperationContext.writeHead
writeResult()
protectedwriteResult(output,encoding?,cb?):boolean
Defined in: packages/core/src/contexts/streamingcontext.ts:71
Keep a non-streamed result
Parameters
output
any
the result
encoding?
string
the encoding to use
cb?
(error) => void
the callback function
Returns
boolean
true