HTTP Request Variables
Request Variables
The following variables are available under the req
namespace:
Name | Type | Description |
---|---|---|
req.content_encoding | list[string] | The encodings set in the Content-Encoding header for this request. |
req.content_length | int64 | 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. |
req.content_type | string | The media type set in the Content-Type header for this request. |
req.content_type.parameters | map[string]string | The parameters set in the Content-Type header for this request. |
req.content_type.raw | string | The value of the Content-Type header for this request. |
req.cookies | map[string][]cookie | 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. |
req.cookies[k][i].name | string | The name of the cookie. |
req.cookies[k][i].value | string | The value of the cookie. |
req.headers | map[string][]string | The request headers parsed as a map of lower-case names to values. |
req.host | string | The value of the host header field for this request. |
req.location | string | The value of the Location header for this request. |
req.method | string | The method for this request. |
req.trailers | map[string][]string | The request trailers parsed as a map of lower-case names to values. |
req.ts.body_received | timestamp | The 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_received | timestamp | The timestamp when ngrok received the header of the request. |
req.url | string | The normalized full URL for this request. |
req.url.authority | string | The authority portion of the URL. |
req.url.host | string | The hostname portion of the host for this request. |
req.url.path | string | The path for this request including the leading forward slash. |
req.url.port | int32 | The port portion of the URL. This may not be present if the URL does not explicitly specify a port. |
req.url.query | string | The full query string for this request excluding the leading question mark. |
req.url.query_params | map[string][]string | The request query string parsed as a map of names to values. |
req.url.raw | string | The un-normalized full URL for this request. |
req.url.raw_path | string | The un-normalized path including the leading slash for this request. |
req.url.scheme | string | The scheme for this request. |
req.url.uri | string | The URI (path and query) portion of the URL. |
req.url.user_password | string | The user:password portion of the URL. |
req.user_agent | string | The value of the User-Agent header for this request. |
req.version | string | The HTTP version for this request. |
req.content_encoding
The encoding set in the Content-Encoding
header for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.content_encoding[0] == 'br'"
// 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.
- YAML
- JSON
# snippet
---
expressions:
- "req.content_length > 10000000"
// snippet
{
"expressions": [
"req.content_length > 10000000"
]
}
req.content_type
The media type set in the Content-Type
header for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.content_type == 'application/json'"
// snippet
{
"expressions": [
"req.content_type == 'application/json'"
]
}
req.content_type.parameters
The parameters set in the Content-Type
header for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.content_type.parameters['charset'] == 'utf-8'"
// snippet
{
"expressions": [
"req.content_type.parameters['charset'] == 'utf-8'"
]
}
req.content_type.raw
The value of the Content-Type
header for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.content_type.raw == 'application/json; charset=utf-8'"
// 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.
- YAML
- JSON
# snippet
---
expressions:
- "size(req.cookies) > 0"
// snippet
{
"expressions": [
"size(req.cookies) > 0"
]
}
req.cookies[k][i].name
The name of the cookie.
- YAML
- JSON
# snippet
---
expressions:
- "req.cookies['sessionId'][0].name == 'sessionId'"
// snippet
{
"expressions": [
"req.cookies['sessionId'][0].name == 'sessionId'"
]
}
req.cookies[k][i].value
The value of the cookie.
- YAML
- JSON
# snippet
---
expressions:
- "req.cookies['sessionId'][0].value > 'value'"
// snippet
{
"expressions": [
"req.cookies['sessionId'][0].value > 'value'"
]
}
req.headers
The request headers parsed as a map of lower-case names to values.
- YAML
- JSON
# snippet
---
expressions:
- "'Fizz' in req.headers['baz']"
// snippet
{
"expressions": [
"'Fizz' in req.headers['baz']"
]
}
req.host
The value of the host header field value for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.host == 'nba.com'"
// snippet
{
"expressions": [
"req.host == 'nba.com'"
]
}
req.location
The value of the Location header for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.location == '/index.html'"
// snippet
{
"expressions": [
"req.location == '/index.html'"
]
}
req.method
The method for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.method == 'POST' || req.method == 'PUT'"
// snippet
{
"expressions": [
"req.method == 'POST' || req.method == 'PUT'"
]
}
req.trailers
The request trailers parsed as a map of lower-case names to values.
- YAML
- JSON
# snippet
---
expressions:
- "'Fizz' in req.trailers['baz']"
// 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.
- YAML
- JSON
# snippet
---
expressions:
- "req.ts.body_received > timestamp('2023-12-31T00:00:00Z')"
// 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.
- YAML
- JSON
# snippet
---
expressions:
- "req.ts.header_received > timestamp('2023-12-31T00:00:00Z')"
// snippet
{
"expressions": [
"req.ts.header_received > timestamp('2023-12-31T00:00:00Z')"
]
}
req.url
The normalized full URL for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.url == 'https://nba.com/')"
// snippet
{
"expressions": [
"req.url == 'https://nba.com/')"
]
}
req.url.authority
The authority portion of the URL.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.authority == 'user:password@nba.com'"
// snippet
{
"expressions": [
"req.url.authority == 'user:password@nba.com'"
]
}
req.url.host
The hostname portion of the host for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.host == 'nba.com'"
// snippet
{
"expressions": [
"req.url.host == 'nba.com'"
]
}
req.url.path
The path for this request including the leading forward slash.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.path.startsWith('/foo')"
// 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.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.port == 443"
// snippet
{
"expressions": [
"req.url.port == 443"
]
}
req.url.query
The full query string for this request excluding the leading question mark.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.query == 'number=23&name=jordan'"
// 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.
- YAML
- JSON
# snippet
---
expressions:
- "'bar' in req.url.query_params['foo']"
// snippet
{
"expressions": [
"'bar' in req.url.query_params['foo']"
]
}
req.url.raw
The un-normalized full URL for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.raw.includes('/foo')"
// snippet
{
"expressions": [
"req.url.raw.includes('/foo')"
]
}
req.url.raw_path
The un-normalized path including the leading slash for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.raw_path.startsWith('/foo')"
// snippet
{
"expressions": [
"req.url.raw_path.startsWith('/foo')"
]
}
req.url.scheme
The scheme for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.scheme == 'https'"
// snippet
{
"expressions": [
"req.url.scheme == 'https'"
]
}
req.url.uri
The URI (path and query) portion of the URL.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.uri.contains('/api/players?number=23&name=jordan')"
// snippet
{
"expressions": [
"req.url.uri.contains('/api/players?number=23&name=jordan')"
]
}
req.url.user_password
The user:password
portion of the URL.
- YAML
- JSON
# snippet
---
expressions:
- "req.url.user_password == 'user:password'"
// snippet
{
"expressions": [
"req.url.user_password == 'user:password'"
]
}
req.user_agent
The value of the User-Agent
header for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.user_agent.contains('curl')"
// snippet
{
"expressions": [
"req.user_agent.contains('curl')"
]
}
req.version
The HTTP version for this request.
- YAML
- JSON
# snippet
---
expressions:
- "req.version == 'HTTP/2.0"
// snippet
{
"expressions": [
"req.version == 'HTTP/2.0"
]
}