Handles the response object or an observable that emits a response object.
This function processes either a ResponseObject or an observable of ResponseObject to send or construct
an HTTP response. It handles different response types such as JSON, HTML, RAW, and STREAM based on the
provided ResponseObject.type. The function also sets appropriate headers, status codes, and formats data
before sending the response to the client.
If the input is an observable, it subscribes to the observable and recursively invokes itself to process
emitted values or handle errors.
The function ensures default values for headers, response status, response type, and data if not provided
explicitly in the ResponseObject.
Response Types:
RESPONSE_TYPE.JSON: Sends a JSON response with a default Content-Type header (application/json; charset=utf-8).
RESPONSE_TYPE.HTML: Sends an HTML response with a default Content-Type header (text/html; charset=utf-8).
RESPONSE_TYPE.RAW: Sends raw data but requires response.header to be set.
RESPONSE_TYPE.STREAM: Streams data to the client but requires response.stream to be set.
Throws
Will throw an error if:
RESPONSE_TYPE.RAW is used without response.header.
RESPONSE_TYPE.STREAM is used without response.stream.
Handles the response object or an observable that emits a response object.
This function processes either a
ResponseObject
or an observable ofResponseObject
to send or construct an HTTP response. It handles different response types such as JSON, HTML, RAW, and STREAM based on the providedResponseObject.type
. The function also sets appropriate headers, status codes, and formats data before sending the response to the client.If the input is an observable, it subscribes to the observable and recursively invokes itself to process emitted values or handle errors.
The function ensures default values for headers, response status, response type, and data if not provided explicitly in the
ResponseObject
.Response Types:
RESPONSE_TYPE.JSON
: Sends a JSON response with a defaultContent-Type
header (application/json; charset=utf-8
).RESPONSE_TYPE.HTML
: Sends an HTML response with a defaultContent-Type
header (text/html; charset=utf-8
).RESPONSE_TYPE.RAW
: Sends raw data but requiresresponse.header
to be set.RESPONSE_TYPE.STREAM
: Streams data to the client but requiresresponse.stream
to be set.Throws
Will throw an error if:
RESPONSE_TYPE.RAW
is used withoutresponse.header
.RESPONSE_TYPE.STREAM
is used withoutresponse.stream
.