urlopen.HttpUserAgent class constructor

The urlopen.HttpUserAgent class is derived from the urlopen.UserAgent class. Use the urlopen.HttpUserAgent() class constructor to create and initialize an HttpUserAgent user agent object.

new urlopen.HttpUserAgent()

Creates and initializes an HttpUserAgent user agent object. The HttpUserAgent object is used when the urlopen.open() API establishes a connection with the target server by HTTP or HTTPS protocol.

Syntax
new urlopen.HttpUserAgent([options])
Parameters
options
A JSON object that consists of properties that are specific to HTTP or HTTPS protocol.
Guidelines
The ua_options parameter can include the following properties. You might not define all properties. Invalid properties make the urlopen.HttpUserAgent() constructor raises exceptions. If you do not specify the ua_options parameter, the default values of the following all properties apply for the created HttpUserAgent object.
allowCompression
Controls whether to allow compression of outbound results and, if the underlying protocol supports compression, negotiate the compression of the returned document. For HTTP or HTTPS, the content-encoding and accept-encoding headers are compression targets. The allowCompression property is Boolean data type. By default, the value is false, which means that compression is disabled.

The allowCompression property in GatewayScript file overrides the var://local/_extension/allow-compression variable and the Allow Compression property that is configured in the user agent for the XML manager.

followRedirect
Controls whether HTTP or HTTPS redirect messages can be followed. The followRedirect property is Boolean data type. By default, the value is true, which means that redirect messages are followed. To prevent HTTP or HTTPS redirects, set the followRedirect property to false.

The followRedirect property in a GatewayScript file overrides the var://local/_extension/donot-follow-redirect variable.

http10Only
Deprecated - Use httpVersion.
httpVersion
Sets the HTTPS version. The httpVersion property is numeric data type.
0
Sets to HTTP/1.0.
1
Sets to HTTP/1.1. This setting is the default value.
2
Sets to HTTP/2.
http2Required
When the HTTP version is HTTP/2, controls whether the connection requires HTTP/2. The http2Required property is Boolean data type. By default, the value is false, which means that HTTP/2 is not required. To require HTTP/2, set the http2Required property to true.
  • For HTTPS, HTTP/2 is enforceable. The server connection is secured with a TLS client profile.
  • For HTTP, HTTP/2 is not enforceable. The server connection is insecure. The server might not honor the upgrade request and process the original request.
keepPayload
Controls how to handle payloads for GET, DELETE, or HEAD requests. The keepPayload property is Boolean data type. By default, the value is false.
  • When the value is false, the payload is ignored for GET, DELETE, or HEAD method.
  • When the value is true, the payload is sent for GET, DELETE, or HEAD method.
persistentConnection
Controls whether to prevent persistent connection. Set the persistentConnection property to false to prevent persistent connections. By default, the persistentConnection property value is true, which indicates that persistent connections are supported by an idle timeout set to 15 seconds.

The persistentConnection property in a GatewayScript file overrides the var://local/_extension/prevent-persistent-connection variable.

maxRedirects
Specifies the maximum number of HTTP or HTTPS redirect messages to receive before the DataPower service declares the target server unreachable. Enter a value in the range 0 - 128. The default value is 8.

The maxRedirects property in GatewayScript file overrides the Maximum Redirects property that is configured in the user agent for the XML manager.

rewriteHost
Controls whether to rewrite the HTTP or HTTPS Host header. The rewriteHost property is Boolean data type. By default, the value is false, which prevents the rewriting of the Host header. When the value is false, the Host header that is defined in the headers property of the options parameter in urlopen.open() API takes effect.

When the value is true, the Host header is rewritten although the var://local/_extension/donot-rewrite-host variable is true. The rewriteHost property in GatewayScript file overrides the var://local/_extension/donot-rewrite-host variable.

Example
Create and initialize the HttpUserAgent object.
var urlopen = require('urlopen');
// define the http-specific user agent properties
var ua_options = {    
    'persistentConnection': false,
    'allowCompression': true,
    'followRedirect': flase,
    'maxRedirects': 16,
    'httpVersion': 2,
    'http2Required' : true,
    'rewriteHost': false
};
var HttpUserAgent = new urlopen.HttpUserAgent(ua_options);