GreasySpoon service provides following information to scripts applying on server responses:
- requestheader : string containing HTTP request header, as generated by user's browser. This header cannot be modified and is only provided in order for your script to adapt processing based on initial request (for example, by changing the response based on the browser type and version provided in the response).
- responseheader : string containing HTTP response header, as returned by the server.
- httpresponse : string containing HTTP response body
- user_id : string containing either user id (login) or user ip address. User ID will be available if authentication is activated on HTTP proxy.
- user_group : string containing user group if available, or null if not. User group might be available if authentication is activated on HTTP proxy.
- sharedcache : a java hash table<String, Object> that is shared between all scripts
Like for requests scripts, information is provided as static variables so can be accessed/modified in any part of the script.
All information is provided as string to avoid casting on Script Engine side, except the shared cache which is transmitted as a Java hashtable. To use this hash table, standard Java methods must be used:
- get(<string>key) to retrieve content associated to given key
- put(<string>key, <object>value) to store a content in the table using given key
Any modification made on HTTP response header and/or body will be handled by GreasySpoon service and will be reflected to the final response provided to the user. Please note that HTTP request header is only provided for potential scripts usage and that changes made on it will be bounded to the script execution context.
In order to illustrate scripts possibilities in response mode, two basic examples are presented hereafter:
- A first basic hello world script in EcmaScript
- A more complex example that takes advantage of ruby libraries. This script demonstrates ruby Hpricot library capacity to manipulate HTML content in a simple way.