Fields and methods of the helma.Http class.
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Http.js')
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Http.js')
Creates a new instance of helma.Http
methods
- setProxy(proxyString)
- getProxy()
- setCredentials(username, password)
- setContent(stringOrObject)
- setMethod(m)
- setHeader(name, value)
- getHeader(name)
- setCookie(name, value)
- getCookie(name)
- setCookies(cookies)
- setTimeout(timeout)
- setReadTimeout(timeout)
- setFollowRedirects(value)
- setUserAgent(agent)
- setBinaryMode(mode)
- setMaxResponseSize(Size)
- setResponseHandler(Response)
- getUrl(url, opt)
- setProxy(proxyString)
- getProxy()
Creates a new instance of helma.Http.Cookie
parameters
String | name | The name of the cookie |
String | value | The value of the cookie |
methods
properties
- String name
- String value
- Date expires
- String path
- String domain
The name of the Cookie
The value of the Cookie
An optional date defining the lifetime of this cookie
An optional path where this cookie is valid
An optional domain where this cookie is valid
An instance of java.text.SimpleDateFormat used for both parsing
an "expires" string into a date and vice versa
A regular expression used for parsing cookie strings
Methods
Sets the proxy host and port for later use. The argument must
be in
host:port
format (eg. "proxy.example.com:3128").parameters
String | proxyString | The proxy to use for this request |
see
Returns the proxy in
host:port
formatreturns
The proxy defined for this request |
see
Sets the credentials for basic http authentication
parameters
String | username | The username |
String | password | The password |
Sets the content to send to the remote server within this request.
parameters
String, Object | stringOrObject | The content of the request, which can be either a string or an object. In the latter case all properties and their values are concatenated into a single string. If a property is an array, then for each value the propertyname and value pair is added. If the name of an array property ends with "_array" then the _array part is removed. |
Sets the request method to use.
parameters
String | m |
The method to use (GET , POST ...)
|
see
Returns the currently defined request method.
returns
The method used |
see
Sets a single HTTP request header field
parameters
String | name | The name of the header field |
String | value | The value of the header field |
see
Returns the value of the request header field with the given name
parameters
String | name | The name of the request header field |
returns
The value of the request header field |
see
Adds a cookie with the name and value passed as arguments
to the list of cookies to send to the remote server.
parameters
String | name | The name of the cookie |
String | value | The value of the cookie |
see
Returns the value of the cookie with the given name
parameters
String | name | The name of the cookie |
returns
The value of the cookie |
see
Adds the cookies passed as argument to the list of cookies to send
to the remote server.
parameters
Array | cookies | An array containing objects with the properties "name" (the name of the cookie) and "value" (the value of the cookie) set. |
Returns all cookies set for this client
returns
An object containing all cookies, where the property name is the name of the cookie, and the value is the cookie value |
see
Sets the connection timeout to the amount of milliseconds
passed as argument
parameters
Number | timeout | The connection timeout in milliseconds |
see
Sets the read timeout (the maximum time a request may take after
the connection has been successfully established) to the amount of
milliseconds passed as argument.
parameters
Number | timeout | The read timeout in milliseconds |
see
Returns the connection timeout
returns
The connection timeout in milliseconds |
see
Returns the read timeout (the maximum time a request may take after
the connection has been successfully established).
returns
The read timeout in milliseconds |
see
Enables or disables following redirects
parameters
Boolean | value | If false this client won't follow redirects (the default is to follow them) |
see
Returns true if the client follows redirects
returns
True if the client follows redirects, false otherwise. |
see
Sets the HTTP "User-Agent" header field to the string passed as argument
parameters
String | agent | The string to use as value of the "User-Agent" header field (defaults to "Helma Http Client") |
see
Returns the value of the HTTP "User-Agent" header field
returns
The value of the field |
see
Switches content text encoding on or off. Depending on this
the content received from the remote server will be either a
string or a byte array.
parameters
Boolean | mode | If true binary mode is activated |
see
Returns the currently defined binary mode of this client
returns
The binary mode of this client |
see
Sets the max allowed size for the response stream
parameters
Integer | Size | in Byte |
Returns the currently set max response size
returns
The max responsesize |
see
Overloads the default response handler.
Use this do implement your own response handling, like storing the response directly to the harddisk
The handler function gets two parameter, first is the java.net.URLConnection and second is the result object.
Note that custom response handler functions should check the HTTP status code before reading
the response. The status code for successful requests is 200. Response bodies for requests with
status codes less than 400 can be read from the connection's input stream, while response bodies
with 4xx or 5xx status codes must be read using the error stream.
parameters
function | Response | handler function |
Get the response handler. This is the function used to read the HTTP response body.
returns
The response handler function |
Executes a http request
parameters
String | url | The url to request |
Date, String | opt | If this argument is a string, it is used as value for the "If-None-Match" request header field. If it is a Date instance it is used as "IfModifiedSince" condition for this request. |
returns
A result object containing the following properties:
|
Evaluates the url passed as argument.
parameters
String | url | The url or uri string to evaluate |
returns
If the argument is a valid url, this method returns a new instance of java.net.URL, otherwise it returns null. |
Sets the global http proxy setting. If no proxy definition
is passed to this method, any existing proxy setting is
cleared. Internally this method sets the system properties
http.proxySet
, http.proxyHost
and
http.proxyPort
. Keep in mind that this is valid for
the whole Java Virtual Machine, therefor using this method
can potentially influence other running Helma applications too!parameters
String | proxyString |
A proxy definition in host:port
format (eg. "proxy.example.com:3128");
|
Returns the proxy setting of the Java Virtual Machine
the Helma application server is running in. If no
proxy is set, this method returns boolean false.
returns
The global proxy setting in host:port
format (eg. "proxy.example.com:3128"), or boolean false.
|
Static helper method to check if a request issued agains a
Helma application is authorized or not.
parameters
String | name | The username to check req.username against |
String | pwd | The password to check req.password against |
returns
True if the request is authorized, false otherwise. In the latter case the current response is reset and the response code is set to "401" ("Authentication required"). |
Parses the cookie string passed as argument into an instance of helma.Http
parameters
String | cookieStr | The cookie string as received from the remote server |
returns
An instance of helma.Http.Cookie containing the cookie parameters |
Returns this cookie in a format useable to set the HTTP header field "Cookie"
returns
This cookie formatted as HTTP header field value |