Retrieve HTTP headers
You can retrieve HTTP headers in your REST operation. There are two methods for doing this.
You can retrieve the header using the WSHeader attribute as part of a function parameter, or your can retrieve headers via WSContext.
The option you choose depends on your requirements:
- Typically, you can pass data to implement logic on the server or client side via headers you
customize using WSHeader and WSName attributes in your function parameter. For
example, the remote address can be passed in a customized HTTP header by specifying an input
parameter with these
attributes:
You can retrieve the remote address in your function using, for example, the statementip_address STRING ATTRIBUTES(WSHeader, WSOptional, WSName="X-FourJs-Environment-Variable-REMOTE_ADDR")
DISPLAY ip_address
.Note:In case the header is not present, you must also set the WSOptional attribute.
- If you do not want the header to be part of the REST operation, you can use the WSContext mechanism. For example, the remote
address and server name can be retrieved by setting a context dictionary variable at the modular
level with the
WSContext
attribute. This allows you to retrieve allX-FourJs-Environment-xxx
set by the GAS by referencing a dictionary key value for the environment variable.In the following example, the dictionary type variable (context) is set with the attributeWSContext
:PRIVATE DEFINE context DICTIONARY ATTRIBUTE(WSContext) OF STRING DISPLAY context["Variable-REMOTE_ADDR"] -- displays the remote ADDR if set by the GAS DISPLAY context["Variable-SERVER_NAME"] -- displays the server name if set by the GAS