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_optionsparameter 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 theua_optionsparameter, 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
allowCompressionproperty is Boolean data type. By default, the value isfalse, which means that compression is disabled.The
allowCompressionproperty 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
followRedirectproperty is Boolean data type. By default, the value istrue, which means that redirect messages are followed. To prevent HTTP or HTTPS redirects, set thefollowRedirectproperty tofalse.The
followRedirectproperty in a GatewayScript file overrides the var://local/_extension/donot-follow-redirect variable. http10Only- Deprecated - Use
httpVersion. httpVersion- Sets the HTTPS version. The
httpVersionproperty 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
http2Requiredproperty is Boolean data type. By default, the value isfalse, which means that HTTP/2 is not required. To require HTTP/2, set thehttp2Requiredproperty totrue.- 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
keepPayloadproperty is Boolean data type. By default, the value isfalse.- 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.
- When the value is
persistentConnection- Controls whether to prevent persistent connection. Set the
persistentConnectionproperty to false to prevent persistent connections. By default, thepersistentConnectionproperty value istrue, which indicates that persistent connections are supported by an idle timeout set to 15 seconds.The
persistentConnectionproperty 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
maxRedirectsproperty 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
Hostheader. TherewriteHostproperty is Boolean data type. By default, the value isfalse, which prevents the rewriting of theHostheader. When the value isfalse, theHostheader that is defined in theheadersproperty of theoptionsparameter in urlopen.open() API takes effect.When the value is
true, theHostheader is rewritten although thevar://local/_extension/donot-rewrite-hostvariable istrue. TherewriteHostproperty 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);