Skip to main content

HTTP Request Variables

Request Variables

The following variables are available under the req namespace:

NameTypeDescription
req.content_encodinglist[string]The encodings set in the Content-Encoding header for this request.
req.content_lengthint64The content length of the body in bytes. This may not be present if the request does not contain a body or if the client does not specify a content length because they are streaming the body.
req.content_typestringThe media type set in the Content-Type header for this request.
req.content_type.parametersmap[string]stringThe parameters set in the Content-Type header for this request.
req.content_type.rawstringThe value of the Content-Type header for this request.
req.cookiesmap[string][]cookieThe HTTP cookie objects included in this request. If there are multiple cookies with the same name, they will be ordered as specified in the Cookie header.
req.cookies[k][i].namestringThe name of the cookie.
req.cookies[k][i].valuestringThe value of the cookie.
req.headersmap[string][]stringThe request headers parsed as a map of lower-case names to values.
req.hoststringThe value of the host header field for this request.
req.locationstringThe value of the Location header for this request.
req.methodstringThe method for this request.
req.trailersmap[string][]stringThe request trailers parsed as a map of lower-case names to values.
req.ts.body_receivedtimestampThe timestamp when ngrok received the body of the request. This may not be present if the request does not contain a body.
req.ts.header_receivedtimestampThe timestamp when ngrok received the header of the request.
req.urlstringThe normalized full URL for this request.
req.url.authoritystringThe authority portion of the URL.
req.url.hoststringThe hostname portion of the host for this request.
req.url.pathstringThe path for this request including the leading forward slash.
req.url.portint32The port portion of the URL. This may not be present if the URL does not explicitly specify a port.
req.url.querystringThe full query string for this request excluding the leading question mark.
req.url.query_paramsmap[string][]stringThe request query string parsed as a map of names to values.
req.url.rawstringThe un-normalized full URL for this request.
req.url.raw_pathstringThe un-normalized path including the leading slash for this request.
req.url.schemestringThe scheme for this request.
req.url.uristringThe URI (path and query) portion of the URL.
req.url.user_passwordstringThe user:password portion of the URL.
req.user_agentstringThe value of the User-Agent header for this request.
req.versionstringThe HTTP version for this request.

req.content_encoding

The encoding set in the Content-Encoding header for this request.

# snippet
---
expressions:
- "req.content_encoding[0] == 'br'"

req.content_length

The content length of the body in bytes. This may not be present if the request does not contain a body or if the client does not specify a content length because they are streaming the body.

# snippet
---
expressions:
- "req.content_length > 10000000"

req.content_type

The media type set in the Content-Type header for this request.

# snippet
---
expressions:
- "req.content_type == 'application/json'"

req.content_type.parameters

The parameters set in the Content-Type header for this request.

# snippet
---
expressions:
- "req.content_type.parameters['charset'] == 'utf-8'"

req.content_type.raw

The value of the Content-Type header for this request.

# snippet
---
expressions:
- "req.content_type.raw == 'application/json; charset=utf-8'"

req.cookies

The HTTP cookie objects included in this request. If there are multiple cookies with the same name, they will be ordered as specified in the Cookie header.

# snippet
---
expressions:
- "size(req.cookies) > 0"

req.cookies[k][i].name

The name of the cookie.

# snippet
---
expressions:
- "req.cookies['sessionId'][0].name == 'sessionId'"

req.cookies[k][i].value

The value of the cookie.

# snippet
---
expressions:
- "req.cookies['sessionId'][0].value > 'value'"

req.headers

The request headers parsed as a map of lower-case names to values.

# snippet
---
expressions:
- "'Fizz' in req.headers['baz']"

req.host

The value of the host header field value for this request.

# snippet
---
expressions:
- "req.host == 'nba.com'"

req.location

The value of the Location header for this request.

# snippet
---
expressions:
- "req.location == '/index.html'"

req.method

The method for this request.

# snippet
---
expressions:
- "req.method == 'POST' || req.method == 'PUT'"

req.trailers

The request trailers parsed as a map of lower-case names to values.

# snippet
---
expressions:
- "'Fizz' in req.trailers['baz']"

req.ts.body_received

The timestamp when ngrok received the body of the request. This may not be present if the request does not contain a body.

# snippet
---
expressions:
- "req.ts.body_received > timestamp('2023-12-31T00:00:00Z')"

req.ts.header_received

The timestamp when ngrok received the header of the request.

# snippet
---
expressions:
- "req.ts.header_received > timestamp('2023-12-31T00:00:00Z')"

req.url

The normalized full URL for this request.

# snippet
---
expressions:
- "req.url == 'https://nba.com/')"

req.url.authority

The authority portion of the URL.

# snippet
---
expressions:
- "req.url.authority == 'user:password@nba.com'"

req.url.host

The hostname portion of the host for this request.

# snippet
---
expressions:
- "req.url.host == 'nba.com'"

req.url.path

The path for this request including the leading forward slash.

# snippet
---
expressions:
- "req.url.path.startsWith('/foo')"

req.url.port

The port portion of the URL. This may not be present if the URL does not explicitly specify a port.

# snippet
---
expressions:
- "req.url.port == 443"

req.url.query

The full query string for this request excluding the leading question mark.

# snippet
---
expressions:
- "req.url.query == 'number=23&name=jordan'"

req.url.query_params

The request query string parsed as a map of names to values.

# snippet
---
expressions:
- "'bar' in req.url.query_params['foo']"

req.url.raw

The un-normalized full URL for this request.

# snippet
---
expressions:
- "req.url.raw.includes('/foo')"

req.url.raw_path

The un-normalized path including the leading slash for this request.

# snippet
---
expressions:
- "req.url.raw_path.startsWith('/foo')"

req.url.scheme

The scheme for this request.

# snippet
---
expressions:
- "req.url.scheme == 'https'"

req.url.uri

The URI (path and query) portion of the URL.

# snippet
---
expressions:
- "req.url.uri.contains('/api/players?number=23&name=jordan')"

req.url.user_password

The user:password portion of the URL.

# snippet
---
expressions:
- "req.url.user_password == 'user:password'"

req.user_agent

The value of the User-Agent header for this request.

# snippet
---
expressions:
- "req.user_agent.contains('curl')"

req.version

The HTTP version for this request.

# snippet
---
expressions:
- "req.version == 'HTTP/2.0"