$req

Global object that contains properties related to the current request.

Summary
$reqGlobal object that contains properties related to the current request.
Properties
authUserIf a “Basic” auth token is supplied ion the header, this function will return the username part, otherwise “”.
authPasswordIf a “Basic” auth token is supplied ion the header, this function will return the password part, otherwise “”.
dataStores parameters to the request.
handledset this to true to prevent requested page from processing
headersa JavaScript Object where the properties are header names and the property values are an array of strings containing each of request header’s values.
timeoutThe maximum time in seconds this request should be allowed to run.
typeThe type of http request.
rawDataStores raw parameters to the request.
idA unique identifier for this request
paramNamesA array of the parameter names passed to this request
contentTextcontent of the request body as a string
contentTypecontent type of the request
contentXmlcontent of the request body as an XML() object
contentByteArraycontent of the request body as a Java byte[]

Properties

authUser

If a “Basic” auth token is supplied ion the header, this function will return the username part, otherwise “”.

authPassword

If a “Basic” auth token is supplied ion the header, this function will return the password part, otherwise “”.

data

Stores parameters to the request.

Detail

Every parameter in the HttpServletRequest is copied as a lowercase property of the data object.

If a parameter is passed multiple times, this property will the last passed value of the parameter.  In addition, a property called <paramName>$array is created.  This property contains an array of all the values of that parameter name, in the order they were passed.  This parameter is created even if only one value is passed

If a parameter value can be interpreted as JSON, a property called <paramName>$object is created by calling String.parseJson against the value.  If there are multiple JSON valid objects, only the last will be stored in parameter_name$object, but a property called parameter_name$objectArray is populated with every object created.

If a parameter contains dots (.) then is is presumed to be a property path and is interpreted via Object.setByPath.  Thus a parameter called “Users.336642.firstName” can be accessed at $req.data.Users[“336642”].firstName

data parameters created via setByPath are not filtered through String.escapeHtml as described below

Every value in data.<paramName> and data.<paramName>$array is escaped via String.escapeHtml.  This helps to protect against Cross-Site Scripting (XSS) and SQL injection.  To access un-altered parameter data, see rawData

File Upload Fields

File uploads produce an object in $req.data containing information about the upload that looks like this

$req.data.<fieldname> ={
diskItem: org.apache.commons.fileupload.disk.DiskFileItem,
stats:{
fieldName:String, name of field in form,
fileName:String, name of file on client side,
contentType:String, mime type,
isInMemory:boolean, true if file contents are in memory,
sizeInBytes:int, size in bytes,
diskLocation:String, the current location of the uploaded file
}
}

multiple uploads with the same fieldname are stored in $req.data.<fieldname>$array.

Upload progress can be tracked in a separate request/Thread via

var progress=$session.get("$uploadProgress");

which returns a progress object.

Progress Object properties

fileNumberFile number currently being uploaded
bytesReadBytes uploaded so far for this file
totalBytesTotal bytes to be uploaded for this file
percentCompletePercent complete as a ratio, from 0 to 1
kpsUpload rate in KiloBytes Per Second.  Multiply this by 8 to get KiloBits per second
messageGeneric message in the form of “Uploading file #1, 10% complete (200 KBps)”;
elapsedSecondstotal time in seconds since upload processing started

handled

set this to true to prevent requested page from processing

headers

a JavaScript Object where the properties are header names and the property values are an array of strings containing each of request header’s values.

Note

Each header is keyed by how it appeared in the header, and as lowercase.  This is because not every server formats header names the same.  This means that if you are looking for a specific header, it is better to use

if ("user-agent" in $req.headers)

rather than

if("User-Agent" in $req.headers)

To avoid confusion when looping over key names, the lowercase key names are hidden and do not show up in Myna.dump() or $req.headers.getKeys()

timeout

The maximum time in seconds this request should be allowed to run. see “Default Request Timeout” in the administrator under General Settings. a value of 0 disables the timeout.

type

The type of http request.  One of GET,POST,PUT or DELETE.

rawData

Stores raw parameters to the request.

Detail

This property contains the same content as data, but without any filtering through String.escapeHtml.  Be very careful displaying this data in a web page as it may expose your site to Cross Site Scripting (XSS) exploits

id

A unique identifier for this request

paramNames

A array of the parameter names passed to this request

contentText

content of the request body as a string

contentType

content type of the request

contentXml

content of the request body as an XML() object

contentByteArray

content of the request body as a Java byte[]

Converts a JSON (http://www.json.org) string into an object
Object.prototype.setByPath=function (path,
value)
sets a property or nested object property of this object
String.prototype.escapeHtml=function(string)
replaces common symbols with their HTML entity equivalents
Stores raw parameters to the request.
Stores parameters to the request.