How do I override the value of the HTTP “Host” header in requests?

Document created by DPM Admin Employee on Jul 21, 2017Last modified by Avril Dsilva on Aug 14, 2017
Version 2Show Document
  • View in full screen mode

For HTTP(s) targets, the Target Editor > Advanced Settings section includes an HTTP “Host” Header Override. This field is used in such cases to override the host header for all messages based on the given HTTP target.

To use this field, open the given HTTP target in the Target Editor, navigate to the Advanced Settings section and then enter the valid host name in the field as an URL and then save the target.

The HTTP host override can also be set on the Target via the Composition Editor > Track (per track name) properties > HttpHostOverride field.

HTTP host overrides can also be performed via placement of a script calling the CloudTest system property, HttpHostOverride in the relevant test clip.

Note that changing the value of the system property via the UI method, or via the deprecated script method, causes only the value in the HTTP “Host” header to be changed, and does not affect the actual location to which the requests are being sent.

This system property can be used to set the value that is sent in the HTTP “Host” header to the host name that the application is expecting. Changing the value of the HttpHostOverride System Property causes only the value in the HTTP “Host” header to be changed, and does not affect the actual location to which the requests are being sent.

 

Use the following steps to override host file(s) for a test using a script instead of the user interface.

 

With Central list > Scripts selected, click New and then create a script that contains the line code on the right. This script will perform a substitution of the IP address in the HTTP Request Header value for Host, to the desired hostname or domain name.

The script will take the value in the Target’s location, whatever it is, an IP or a domain name, and replace it at runtime with the value entered.

$context.currentItem.nextItem.target.systemPropertyList.setPropertyValue
("HttpHostOverride", "YOUR_URL");

  1. From Central list > Test Clips, either open or create a test clip in which the override will take place.
  2. Place the script into the test clip at the location specified by the $context used in your script. For example, place the script prior to the message whose Target location you want to override if you used:

    $context.currentItem.nextItem.
  3. Next, ensure that the scope of the message to override (in this example, the one directly after the script in the test clip) is set to at least local or  public.

Refer to Setting and Using Message Scope for more information about message scope.

  1. Save the test clip once scope is set on any message the script will access.

When the test composition is played, the host of the target will be overwritten with the system property set in the script. You can verify this substitution in the Composition Editor > Results tab > Result Details widget by selecting the target in the cover flow at the top and then clicking the Events List tab.

Attachments

    Outcomes