Spirent Avalanche 5.46 February 29, 2024

Apply Variables

After you ASSIGN a run-time value to a variable, use APPLY to apply the value. You can also use APPLY with the URLENC parameter to URL encode the runtime value of an applied variable.

Syntax

To apply a value to a variable use the following syntax:

<APPLY variable_name>

HTTP/HTTPS

An HTTP/HTTPS action can be any combination of one or more variables and strings. The methods, GET, POST, HEAD, PUT, and DELETE (HTTPDEL), support multiple APPLY statements in one URL.

NOTE: See the following sections for limitations and considerations:

Examples

The following sections contain examples of various uses of the APPLY statement in HTTP Action lists.

NOTE: All examples for HTTP apply to HTTPS as well.

GET Examples:

NOTE: All examples for the GET method apply to HEAD as well.

POST Examples:

PUT Examples:

DELETE (HTTPDEL) Examples:

GET: Use APPLY to replace IP address or other variables

ASSIGN VARIABLE <my_host "192.168.58.1">

Result:

1 GET http://192.168.58.1/

NOTE: Since the example above applies the host field from a variable, a slash ("/") is automatically added after the host field in the URL sent to the server.

Result:

1 GET http://192.168.58.1/index.html

ASSIGN VARIABLE <my_path "download">

1 GET http://192.168.58.1/<APPLY my_path>/index.html

Result:

1 GET http://192.168.58.1/download/index.html

ASSIGN VARIABLE <my_name "user1">

1 GET http://192.168.58.1:80/download/index.html?user=<APPLY my_name>

Result:

1 GET http://192.168.58.1:80/download/index.html?user=user1

GET: Use multiple APPLY statements in one URL

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 GET http://192.168.1.1/abc/def/index.html?user=apple&password=bill

ASSIGN VARIABLE <my_host "192.168.1.1">

ASSIGN VARIABLE <my_path "download">

ASSIGN VARIABLE <my_file "index.html">

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 GET http://192.168.1.1:80/download/index.html?user=apple&password=bill

ASSIGN VARIABLE <my_host_port2 "192.168.1.1:80">

ASSIGN VARIABLE <my_path "path1/path2/path3">

ASSIGN VARIABLE <my_query "?emailid=abc@spirent.com&attid=abc_attid">

Result:

1 GET http://192.168.1.1:80/path/path1/path2/path3/dir1/dir2?emailid=abc@spirent.com&attid=abc_attid

ASSIGN VARIABLE <SIGNATURE_VAR "abc_signature">

ASSIGN VARIABLE <PATH "something/abc_signature/something">

ASSIGN VARIABLE <EMAILID_VAR "abc@spirent.com">

ASSIGN VARIABLE <ATTID_VAR "abc_attid">

ASSIGN VARIABLE <ATTID_VAR2 "&attid=abc_attid">

ASSIGN VARIABLE <QUERY_VAR "?emailid=abc@spirent.com&attid=abc_attid">

Result:

1 GET http://192.168.58.1/something/abc_signature/something/something?emailid=abc@spirent.com&attid=abc_attid

Result:

1 GET http://192.168.58.1/something/abc_signature/something/something?emailid=abc@spirent.com&attid=abc_attid

Result:

1 GET http://192.168.58.1/something/abc_signature/something/something?emailid=abc@spirent.com&attid=abc_attid

NOTE: The three results above are identical.

Result:

1 GET http://192.168.58.1/something/abc_signature/something/index.html?emailid=abc@spirent.com&attid=abc_attid

NOTE: The example above uses slash ("/") separators in the PATH variable. Other characters, such as ":", "?", and "=", are also allowed in variables.

ASSIGN VARIABLE <my_host "192.168.58.1">

ASSIGN VARIABLE <my_host_port "192.168.58.1:80">

ASSIGN VARIABLE <my_name "user1">

Result:

1 GET http://192.168.58.1/download/index.html?user=user1

Result:

1 GET http://192.168.58.1:80/download/index.html?user=user1

GET: Use multiple APPLY statements with a forms database

The following example uses variables from a forms database named FormsDB_1, which contains a list of IP addresses, such as 192.168.58.1, 192.168.58.2, etc.

ASSIGN VARIABLE <var_IP FormsDB_1.$1>

ASSIGN VARIABLE <my_path "download">

1 GET http://<APPLY var_IP>/<APPLY my_path>/index.html

Result:

1 GET http://192.168.58.1/download/index.html

1 GET http://192.168.58.2/download/index.html

.

.

.

POST: Post captured session ID

The following example assumes that you have captured a sessionId equal to "ABCD" (e.g., by using search criteria), and saved it in the captured_session variable. It POSTs the sessionId, along with other key/value pairs, as follows:

1 POST http://10.30.7.220/ sessionId=<APPLY BODY captured_session> key1=value1 key2=value2

The resulting BODY is as follows:

POST / sessionId=ABCD&key1=value1&key2=value2

NOTE: If you use the HEADER modifier instead of BODY in the APPLY statement, then the value of captured_session is applied to the HTTP request URI.

POST: Add suffix to captured session ID and post

The following example assumes that you have captured a sessionId equal to "ABCD" (e.g., by using search criteria), and saved it in the captured_session variable. The sessionId is suffixed with "XYZ" and sent by using a POST, along with other key/value pairs, as follows:

1 POST http://10.30.7.220/ sessionId=<APPLY BODY captured_session, "XYZ"> key1=value1 key2=value2

The resulting BODY is as follows:

POST / sessionId=ABCDXYZ&key1=value1&key2=value2

POST: Add prefix to captured session ID and post

The following example assumes that you have captured a sessionId equal to "ABCD" (e.g., by using search criteria), and saved it in the captured_session variable. The sessionId is prefixed with "XYZ" and sent by using a POST, along with other key/value pairs, as follows:

1 POST http://10.30.7.220/ sessionId=XYZ<APPLY BODY captured_session> key1=value1 key2=value2

The resulting BODY is as follows:

POST / sessionId=XYZABCD&key1=value1&key2=value2

POST: Use multiple APPLY statements in one URL

ASSIGN VARIABLE <my_host_port2 "192.168.1.1:80">

ASSIGN VARIABLE <my_path "path1/path2/path3">

ASSIGN VARIABLE <my_email "abc@spirent.com">

ASSIGN VARIABLE <my_var "abc_attid">

ASSIGN VARIABLE <my_query "?emailid=abc@spirent.com&attid=abc_attid">

Result:

1 POST http://192.168.1.1/path/path1/path2/path3/dir1/dir2?emailid=abc@spirent.com&attid=abc_attid

Result:

1 POST http://192.168.1.1/path/path1/path2/path3/dir1/dir2?emailid=abc@spirent.com&attid=abc_attid

Result:

1 POST http://192.168.1.1:80/path/path1/path2/path3/dir1/dir2?emailid=abc@spirent.com&attid=abc_attid

ASSIGN VARIABLE <my_host "192.168.1.1">

ASSIGN VARIABLE <my_path "download">

ASSIGN VARIABLE <my_file "index.html">

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 POST HTTP://192.168.1.1:80/download/index.html?user=apple&password=bill

POST: Use multiple APPLY statements with a forms database

The following example uses variables from a forms database named FormDB, which contains the following sample row:

192.168.1.1,path1/path2/path3,abc@spirent.com,abc_attid,abc,xyz

For this example, the following parameters are defined from the forms database columns:

ASSIGN VARIABLE <my_host FormDB.$1>

ASSIGN VARIABLE <my_dir FormDB.$2>

ASSIGN VARIABLE <my_email FormDB.$3>

ASSIGN VARIABLE <my_atti FormDB.$4>

ASSIGN VARIABLE <my_user FormDB.$5>

ASSIGN VARIABLE <my_pwd FormDB.$6>

Result:

1 POST HTTP://192.168.1.1/path1/path2/path3/index.html?emailid=abc@spirent.com&attid=abc_attid user=abc&pass=xyz

PUT: Use multiple APPLY statements in one URL

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 PUT http://192.168.1.1/abc/def/index.html?user=apple&password=bill

ASSIGN VARIABLE <my_host "192.168.1.1">

ASSIGN VARIABLE <my_path "download">

ASSIGN VARIABLE <my_file "index.html">

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 PUT HTTP://192.168.1.1:80/download/index.html?user=apple&password=bill

ASSIGN VARIABLE <my_host_port2 "192.168.1.1:80">

ASSIGN VARIABLE <my_path "path1/path2/path3">

ASSIGN VARIABLE <my_query "?emailid=abc@spirent.com&attid=abc_attid">

Result:

1 PUT http://192.168.1.1:80/path/path1/path2/path3/dir1/dir2?emailid=abc@spirent.com&attid=abc_attid

DELETE (HTTPDEL): Use multiple APPLY statements in one URL

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 HTTPDEL http://192.168.1.1/abc/def/index.html?user=apple&password=bill

ASSIGN VARIABLE <my_host "192.168.1.1">

ASSIGN VARIABLE <my_path "download">

ASSIGN VARIABLE <my_file "index.html">

ASSIGN VARIABLE <my_user "apple">

ASSIGN VARIABLE <my_pwd "bill">

Result:

1 HTTPDEL http://192.168.1.1:80/download/index.html?user=apple&password=bill

ASSIGN VARIABLE <my_host_port2 "192.168.1.1:80">

ASSIGN VARIABLE <my_path "path1/path2/path3">

ASSIGN VARIABLE <my_query "?emailid=abc@spirent.com&attid=abc_attid">

Result:

1 HTTPDEL http://192.168.1.1:80/path/path1/path2/path3/dir1/dir2?emailid=abc@spirent.com&attid=abc_attid

Specify HTTP/HTTPS port number in APPLY

If you do not specify a port number in a request, the default is 80 for HTTP, and 443 for HTTPS. If the host is a variable, and you want to use a different port number, then you must put the host and port numbers into the same APPLY statement, separated by a  colon (":").

Example

ASSIGN VARIABLE <my_host_port "192.168.58.1:8080">

1 GET HTTP://<APPLY my_host_port>/download/index.html

Add slash ("/") after host field

By definition, the absolute path in an HTTP/HTTPS request cannot be empty. If absent from the original URI, the path must be specified as "/" (the server root).

Examples of automatic slash

If you do not specify a slash ("/") after the host field, or if the host field is applied from a variable, then a slash ("/") will be automatically added after the host field in the URL sent to the server. (This is a client requirement per RFC 2616. If the client does not include this slash, the server will respond with an error.)

Configured:

http://192.168.58.1

 

Sent:

http://192.168.58.1/

 

Configured:

ASSIGN VARIABLE <my_host "192.168.58.1">

1 http://<apply my_host>

 

Sent:

http://192.168.58.1/

Examples of duplicate slash

In some cases, two slashes may result. For example, you may specify a slash after the host field, and another may be automatically added.

Configured:

ASSIGN VARIABLE <my_host "192.168.58.1">

1 http://<apply my_host>/index.html

 

Sent:

http://192.168.58.1//index.html

 

Configured:

ASSIGN VARIABLE <my_file "/login.html">

1 https://192.168.58.1<apply my_file>

 

Sent:

https://192.168.58.1//login.html

NOTE: Usually, the HTTP server can handle duplicate slashes, and consider them as one slash. However, you can avoid duplicate slashes with your syntax. In the examples above, do the following:

  • Omit the slash after the host field:

1 http://<apply my_host>index.html

  • Assign the variable as "login" instead of "/login":

ASSIGN VARIABLE <my_file "login.html">


Assign Variables

HTTP Action Lists

HTTP Additional Headers with Variables

HTTP URL Encode

HTTP/HTTPS Action List Format Examples

HTTP/HTTPS Search

HTTP Match and Match Not

© 2024 Spirent Communications, Inc. All Rights Reserved.