What are Implicite Pipeline Objects?
Inside any pipeline there are objects automatically provided to you at execution time which can be accessed without any further allocation steps. Such an object is called Implicite Pipeline Object. These objects can be accessed using the Pipeline Expression Language (PEL). Some of them are read-only and some are read-write:
vars
headers
body
request
response
exception
vars
SINCE VERSION 1.0
This object gives you access to all variables of the current pipeline.
Let's assume, you have defined a variable counter
and you would like to access this counter in your expression, then you could write an expression like this:
${vars.counter}
Here is an example of a pipeline which declares this variable and uses the Pipeline Expression to output the value of counter
to the body:
vars: counter: 12 pipeline: - body.set: value: "The counter is: ${vars.counter}"
This will result in an output like this:
The counter is: 12
Also see Pipeline Expression Language (PEL) .
headers
SINCE VERSION 1.0
This object gives you access to all pipeline headers of the current pipeline.
Do not mix up Pipeline headers with HTTP headers. The latter can be accessed using the ${context.request.headers}
object instead.
Here is an example of a pipeline which accesses the header attribute contentType
and writes it to the body:
headers: contentType: "text/plain" pipeline: - body.set: value: "The type is: ${headers.contentType}"
This will result in an output like this:
The type is: text/plain
Also see Pipeline Expression Language (PEL) .
body
SINCE VERSION 1.0
This object gives you access to the current body of the current pipeline.
Here is an example which defines an initial body value and replaces this with another text in the pipeline:
body: "Hello World" pipeline: - body.set: value: "The text from body is: ${body}"
This will result in an output like this:
The text from body is: Hello World
Also see Pipeline Expression Language (PEL) .
response
SINCE VERSION 9.0
This object gives you access to the response of the current request. You can set the response status or headers for example.
The response
object is only set in case this pipeline was triggered by an initial HTTP request. Otherwise, this object is null
.
Here is an example which sets the HTTP 401 on the current request:
pipeline: - body.set: ${context.response.statusCode = 401}
This will result in an output like this:
401
And it will return the HTTP Status code 401 to the client.
You can also use the command http.response.set in order to set the response values:
pipeline: - http.response.set: statusCode: 401 headers: X-Special: "MyValue"
Note: The final body of the pipeline will become the body for the response, therefore you cannot set it on the response implicit object.
These are the attributes accessible via the response
object:
response.statusCode
The HTTP status to send back to the client. One of: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
response.headers
A key-value map which contains the headers to be send back to the client.
request
SINCE VERSION 9.0
This object gives you access to the current request object, if there is any.
Here is an example which reads the contentType
header from the current request:
pipeline: - body.set: "ContentType is: ${request.headers['content-type']}"
This will result in an output like this:
ContentType is: application/json
The request
object is only available in case this pipeline was triggered by an initial HTTP request. Otherwise, this object is null
.
These are the attributes accessible via the request
object:
request.headers
A key-value map of all HTTP request headers of the current request.
The HTTP request header keys are all lower cased in this map!
request.params
A key-value map of all HTT request query parameters of the current request.
request.protocol
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion
, for example, HTTP/1.1
.
request.contentLength
The content length of the current request in bytes.
request.contentType
The Content-Type header of the current request. One of the standard content types or a custom one.
request.requestPath
The request path of current request without hostname.
request.method
The HTTP method used for this request.
request.locale
The locale used for this request or null if none was set.
request.cookies
The list of cookies linked to this request.
request.cookies[].name
Returns the name of the cookie. The name cannot be changed after creation.
request.cookies[].value
Returns the value of the cookie as string.
request.cookies[].path
Returns the path as string on the server to which the browser returns this cookie. The cookie is visible to all subpaths on the server.
request.cookies[].version
Returns the version integer of the protocol this cookie complies with. Version 1 complies with RFC 2109, and version 0 complies with the original cookie specification drafted by Netscape. Cookies provided by a browser use and identify the browser's cookie version.
request.cookies[].domain
Returns the domain name set for this cookie as string. The form of the domain name is set by RFC 2109.
request.cookies[].comment
Returns the comment string describing the purpose of this cookie, or null
if the cookie has no comment.
request.cookies[].maxAge
Returns the maximum age of the cookie, specified in seconds. By default, -1 indicating the cookie will persist until browser shutdown.
request.cookies[].secure
Returns true
if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol.
request.cookies[].httpOnly
Gets the flag that controls if this cookie will be hidden from scripts on the client side. Returns true
if the cookie is hidden from scripts, else false
.
exception
SINCE VERSION 9.0
In case an exception happened in this pipeline, this object will contain all required information about it. Otherwise this object is null
.
exception.message
Returns the exception message as string.
exception.type
Returns the type (name) of the current exception. Example values (could also be dynamic ones):
HTTP400BadRequestException
HTTP403ForbiddenException
HTTP404NotFoundException
HTTP409ConflictException
HTTP410GoneException
HTTP411ContentLengthRequiredException
HTTP429TooManyRequestsException
HTTP500InternalServerError
PelUtilException
CommandExecutionException
CommandNotFoundException
PipelineException
Exception
exception.uuid
Returns the unique id of this exception. This is handy for searching in logs for this exact match.
exception.time
The unix timestamp in millis when this exception happened at the backend.
0 Comments