addResponseHeaderField
addResponseHeaderField(name: String; value: String) updating, final;
The addResponseHeaderField method of the JadeRestService class enables you to add HTTP header fields for an individual Direct REST response, in addition to the automatically generated "Content‑Type" and "Content‑Length" headers. You can specify one or more custom header fields for a single REST response.
The specified name and value parameters will generate a header field where the name and value are separated by a colon (:) character. The specified values are case‑insensitive. If the same header name is re‑used, the last value that was added will be used.
The name parameter:
-
Cannot be empty ("")
-
Is alpha-numeric in the range 0 through 9, a through z, and A through Z
-
Can contain the following characters: ! # $ % & ' * + - . ^ _ ` | ~
-
Cannot contain "Content-Length"
The value parameter:
-
Cannot be empty
-
Is printable or Tab (0x09, 0x20 through 0xFF)
The following example shows the use of this method to set the "Content‑Type" header field of the response to a Portable Network Graphics (.png) image.
getImagePng(filename: String): Binary updating; vars file : File; begin addResponseHeaderField("Content-Type","image/png"); create file; file.mode := File.Mode_Input; file.kind := File.Kind_Binary; file.fileName := "c:\somepath\" & filename; return file.readBinary(file.fileLength()); epilog delete file; end;
A REST response with a binary payload is generated when the return type of the method is the
Invalid data results in exception 1002 (Invalid parameter value) being raised.
All custom headers are removed before the Direct REST request is processed; that is, you must call the addResponseHeaderField method for each response that requires a custom header.
Remember to call this method to set the "Content‑Type" header field for Direct REST service methods returning binary payloads.
2022.0.05 and higher