r.headersOut['Set-Cookie'] = ['aaa', 'bbb'];
r.headersOut['Foo'] = ['aaa', 'bbb'];
- r.subrequest('/uri', reply => r.return(200, reply.headersOut["Location"] ?? ''));
-
// r.log
r.log(bs);
r.variables.a == 'a';
r.variables.cookie_a = 'b';
+ // r.rawVariables
+ r.rawVariables.a?.equals(Buffer.from([1]));
+
// r.subrequest
+ r.subrequest('/uri', reply => r.return(200, reply.headersOut["Location"] ?? ''));
r.subrequest('/p/sub1').then(reply => r.return(reply.status));
r.subrequest('/p/sub2', {method:'POST'}).then(reply => r.return(reply.status));
vod = r.subrequest('/p/sub3', reply => r.return(reply.status));
// Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply => r.return(reply.status));
r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
JSON.stringify(JSON.parse(reply.responseBody ?? ''))));
+
+ // r.requestText
+ r.requestText == 'a';
+ r.requestText?.startsWith('a');
+
+ // r.requestBuffer
+ r.requestBuffer?.equals(Buffer.from([1]));
+
+ // r.responseText
+ r.responseText == 'a';
+ r.responseText?.startsWith('a');
+
+ // r.responseBuffer
+ r.responseBuffer?.equals(Buffer.from([1]));
}
function fs_module() {
[prop: string]: NjsStringLike | undefined;
}
+/**
+ * @since 0.5.0
+ */
+type NginxRawVariables = {
+ [K in keyof NginxVariables]: Buffer | undefined;
+};
+
interface NginxSubrequestOptions {
/**
* Arguments string, by default an empty string is used.
* To ensure that the client request body is in memory, its size should be
* limited by client_max_body_size, and a sufficient buffer size should be set
* using client_body_buffer_size. The property is available only in the js_content directive.
+ *
+ * @since 0.5.0
+ */
+ readonly requestBuffer?: Buffer;
+ /**
+ * The same as `requestBuffer`, but returns a string.
+ *
+ * **Warning:** It may convert bytes invalid in UTF-8 encoding into the replacement character.
+ *
+ * @see requestBuffer
+ * @since 0.5.0
+ */
+ readonly requestText?: NjsByteString;
+ /**
+ * The same as `requestBuffer`, but returns a string.
+ *
+ * **Warning:** It may convert bytes invalid in UTF-8 encoding into the replacement character.
+ *
+ * @see requestBuffer
+ * @see requestText
+ * @deprecated Use `requestText` or `requestBuffer` instead.
*/
readonly requestBody?: NjsByteString;
/**
* Subrequest response body. The size of response body is limited by
* the subrequest_output_buffer_size directive.
+ *
+ * @since 0.5.0
+ */
+ readonly responseBuffer?: Buffer;
+ /**
+ * The same as `responseBuffer`, but returns a string.
+ *
+ * **Warning:** It may convert bytes invalid in UTF-8 encoding into the replacement character.
+ *
+ * @see responseBuffer
+ */
+ readonly responseText?: NjsByteString;
+ /**
+ * The same as `responseBuffer`, but returns a string.
+ *
+ * **Warning:** It may convert bytes invalid in UTF-8 encoding into the replacement character.
+ *
+ * @see responseBuffer
+ * @see responseText
+ * @deprecated Use `responseText` or `responseBuffer` instead.
*/
readonly responseBody?: NjsByteString;
/**
*/
readonly uri: NjsByteString;
/**
- * nginx variables object.
+ * nginx variables as Buffers.
+ *
+ * @since 0.5.0
+ * @see variables
+ */
+ readonly rawVariables: NginxRawVariables;
+ /**
+ * nginx variables as strings.
+ *
+ * **Warning:** Bytes invalid in UTF-8 encoding may be converted into the replacement character.
+ *
+ * @see rawVariables
*/
readonly variables: NginxVariables;
/**
[prop: string]: NjsByteString | undefined;
}
+/**
+ * @since 0.5.0
+ */
+type NginxStreamRawVariables = {
+ [K in keyof NginxStreamVariables]: Buffer | undefined;
+};
+
interface NginxStreamCallbackFlags {
/**
* True if data is a last buffer.
log(message: NjsStringOrBuffer): void;
/**
* Unregisters the callback set by on() method.
+ * @param event Event type to unregister.
*/
- off(event: "upload" | "download"): void;
+ off(event: "upload" | "download" | "upstream" | "downstream"): void;
/**
* Registers a callback for the specified event.
+ * @param event Event type to register. The callback data value type
+ * depends on the event type. For "upload" | "download" the data type is string.
+ * For "upstream" | "downstream" the data type is Buffer.
+ * String and buffer events cannot be mixed for a single session.
+ *
+ * **Warning:** For string data type bytes invalid in UTF-8 encoding may be
+ * converted into the replacement character.
*/
on(event: "upload" | "download",
- callback:(data:NjsByteString, flags: NginxStreamCallbackFlags) => void): void;
+ callback: (data: NjsByteString, flags: NginxStreamCallbackFlags) => void): void;
+ on(event: "upstream" | "downstream",
+ callback: (data: Buffer, flags: NginxStreamCallbackFlags) => void): void;
/**
* Client address.
*/
*/
send(data: NjsStringOrBuffer, options?: NginxStreamSendOptions): void;
/**
- * nginx variables object.
+ * nginx variables as Buffers.
+ *
+ * @since 0.5.0
+ * @see variables
+ */
+ readonly rawVariables: NginxStreamRawVariables;
+ /**
+ * nginx variables as strings.
+ *
+ * **Warning:** Bytes invalid in UTF-8 encoding may be converted into the replacement character.
+ *
+ * @see rawVariables
*/
readonly variables: NginxStreamVariables;
/**