Retrieve HTTP headers

You can retrieve HTTP headers in your REST operation.

There are different ways for retrieving HTTP headers; such as using the WSHeader attribute as part of a function parameter, or retrieving headers via WSContext.

The option you choose depends on your requirements:
  • If you need to retrieve the header as part of the REST operation, you use WSHeader and WSName attributes in your function parameter. You can retrieve any HTTP header in this way. In case the header is not present, you must also set the WSOptional attribute. For example, the remote address can be passed in the header by coding:
    ip_address STRING ATTRIBUTES(WSHeader, WSOptional, WSName="X-FourJs-Environment-Variable-REMOTE_ADDR") 
  • 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 (for example context) at the modular level with the WSContext attribute. This allows you to retrieve all X-FourJs-Environment-xxx set by the GAS by referencing a dictionary key value for the environment variable:
    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