# WsRequest

## Overview

`WsRequest` represents an HTTP request in a REST-WS environment, offering comprehensive methods to retrieve and manipulate request data. The class provides access to request headers, parameters, cookies, content, and metadata such as character encoding, content type, and request method. Additionally, it supports retrieving information about the client, server, and request path.

Key capabilities include retrieving request headers and their values (`getHeader`, `getHeaders`), managing request parameters (`getParameter`, `getParameterMap`), and accessing cookies (`getCookies`). It also allows obtaining the body content of the request (`getContents`) and metadata such as the query string (`getQueryString`), server name (`getServerName`), and remote address (`getRemoteAddr`). The class also supports advanced features like handling multi-part requests and obtaining localized language preferences (`getLocaleLanguageTag`).

## Properties Summarized

| Type                                                                         | Name                                    | Summary                                                                      |
| ---------------------------------------------------------------------------- | --------------------------------------- | ---------------------------------------------------------------------------- |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [characterEncoding](#characterencoding) | Returns the name of the character encoding used in the body of this request. |

## Methods Summarized

| Type                                                                           | Name                                                 | Summary                                                                                                                                                                                     |
| ------------------------------------------------------------------------------ | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getContentLength()](#getcontentlength)              | Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.                                                                 |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getContentType()](#getcontenttype)                  | Returns the MIME type of the body of the request, or `null` if the type is not known.                                                                                                       |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getContents()](#getcontents)                        | Get raw the contents of the request.                                                                                                                                                        |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getContextPath()](#getcontextpath)                  | Returns the portion of the request URI that indicates the context of the request.                                                                                                           |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getCookies()](#getcookies)                          | Returns an array containing all of the `Cookie` objects the client sent with this request.                                                                                                  |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getDateHeader(name)](#getdateheader-name)           | Returns the value of the specified request header as a `long` value that represents a `Date` object.                                                                                        |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getHeader(name)](#getheader-name)                   | Returns the value of the specified request header as a String.                                                                                                                              |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getHeaderNames()](#getheadernames)                  | Returns an enumeration of all the header names this request contains.                                                                                                                       |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getHeaders(name)](#getheaders-name)                 | Returns all the values of the specified request header as an array of `String` objects.                                                                                                     |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getIntHeader(name)](#getintheader-name)             | Returns the value of the specified request header as an `int`.                                                                                                                              |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getLocalAddr()](#getlocaladdr)                      | Returns the Internet Protocol (IP) address of the interface on which the request was received.                                                                                              |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getLocalName()](#getlocalname)                      | Returns the host name of the Internet Protocol (IP) interface on which the request was received.                                                                                            |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getLocalPort()](#getlocalport)                      | Returns the Internet Protocol (IP) port number of the interface on which the request was received.                                                                                          |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getLocaleLanguageTag()](#getlocalelanguagetag)      | Returns the preferred `Locale` that the client will accept content in, based on the Accept-Language header.                                                                                 |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getLocalesLanguageTags()](#getlocaleslanguagetags)  | Returns an array of `Locale` objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getMethod()](#getmethod)                            | Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.                                                                                       |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getParameter(name)](#getparameter-name)             | Returns the value of a request parameter as a `String`, or `null` if the parameter does not exist.                                                                                          |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [getParameterMap()](#getparametermap)                | Returns an object of the parameters of this request.                                                                                                                                        |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getParameterNames()](#getparameternames)            | Returns an array of `String` objects containing the names of the parameters contained in this request.                                                                                      |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getParameterValues(name)](#getparametervalues-name) | Returns an array of `String` objects containing all of the values the given request parameter has, or `null` if the parameter does not exist.                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getPathInfo()](#getpathinfo)                        | Returns any extra path information associated with the URL the client sent when it made this request.                                                                                       |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getPathTranslated()](#getpathtranslated)            | Returns any extra path information after the servlet name but before the query string, and translates it to a real path.                                                                    |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getProtocol()](#getprotocol)                        | Returns the name and version of the protocol the request uses in the form \*protocol/majorVersion.                                                                                          |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getQueryString()](#getquerystring)                  | Returns the query string that is contained in the request URL after the path.                                                                                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getRealPath(path)](#getrealpath-path)               | Gets the *real* path corresponding to the given *virtual* path.                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getRemoteAddr()](#getremoteaddr)                    | Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.                                                                                               |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getRemoteHost()](#getremotehost)                    | Returns the fully qualified name of the client or the last proxy that sent the request.                                                                                                     |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getRemotePort()](#getremoteport)                    | Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.                                                                                           |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getRequestURI()](#getrequesturi)                    | Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.                                                                 |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getRequestURL()](#getrequesturl)                    | Reconstructs the URL the client used to make the request.                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getScheme()](#getscheme)                            | Returns the name of the scheme used to make this request, for example, `http`, `https`, or `ftp`.                                                                                           |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getServerName()](#getservername)                    | Returns the host name of the server to which the request was sent.                                                                                                                          |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)   | [getServerPort()](#getserverport)                    | Returns the port number to which the request was sent.                                                                                                                                      |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [getServletPath()](#getservletpath)                  | Returns the part of this request's URL that calls the servlet.                                                                                                                              |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [isSecure()](#issecure)                              | Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.                                                                                           |

## Properties Detailed

### characterEncoding

Returns the name of the character encoding used in the body of this request. This method returns `null` if the request does not specify a character encoding

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the name of the character encoding, or `null` if the request does not specify a character encoding

## Methods Detailed

### getContentLength()

Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. For HTTP servlets, same as the value of the CGI variable CONTENT\_LENGTH.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) a long containing the length of the request body or -1L if the length is not known

### getContentType()

Returns the MIME type of the body of the request, or `null` if the type is not known. For HTTP servlets, same as the value of the CGI variable CONTENT\_TYPE.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the name of the MIME type of the request, or null if the type is not known

### getContents()

Get raw the contents of the request.

In case of multipart request, all uploaded items are listed separately.\
In case of a request with a single body, the contents array consists of one item, the body.

This method returns an empty array if the request has no contents.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of WsContents objects.

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
```

### getContextPath()

Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.

It is possible that a servlet container may match a context by more than one context path. In such cases this method will return the actual context path used by the request and it may differ from the path returned by the javax.servlet.ServletContext#getContextPath() method. The context path returned by javax.servlet.ServletContext#getContextPath() should be considered as the prime or preferred context path of the application.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` specifying the portion of the request URI that indicates the context of the request

### getCookies()

Returns an array containing all of the `Cookie` objects the client sent with this request. This method returns an empty array if no cookies were sent.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of all the `Cookies` included with this request

### getDateHeader(name)

Returns the value of the specified request header as a `long` value that represents a `Date` object. Use this method with headers that contain dates, such as `If-Modified-Since`.

The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.

If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an `IllegalArgumentException`.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **name** a `String` specifying the name of the header

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) a `long` value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the request

### getHeader(name)

Returns the value of the specified request header as a String.\
If the request did not include a header of the specified name, this method returns null.\
If there are multiple headers with the same name, this method returns the first head in the request.\
The header name is case insensitive. You can use this method with any request header.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **name** The name of the header to get

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) The value of the specified request header as a String, or null if the header is not present.

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var header = request.getHeader('');
```

### getHeaderNames()

Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration.

Some servlet containers do not allow servlets to access headers using this method, in which case this method returns `null`

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an enumeration of all the header names sent with this request; if the request has no headers, an empty enumeration; if the servlet container does not allow servlets to use this method, `null`

### getHeaders(name)

Returns all the values of the specified request header as an array of `String` objects.

Some headers, such as `Accept-Language` can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.

If the request did not include any headers of the specified name, this method returns an empty array. The header name is case insensitive. You can use this method with any request header.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **name** a `String` specifying the header name

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array containing\
&#x20;                    the values of the requested header. If\
&#x20;                    the request does not have any headers of\
&#x20;                    that name return an empty\
&#x20;                    enumeration. If\
&#x20;                    the container does not allow access to\
&#x20;                    header information, return null

### getIntHeader(name)

Returns the value of the specified request header as an `int`. If the request does not have a header of the specified name, this method returns -1. If the header cannot be converted to an integer, this method throws a `NumberFormatException`.

The header name is case insensitive.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **name** a `String` specifying the name of a request header

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) an integer expressing the value\
&#x20;               of the request header or -1\
&#x20;               if the request doesn't have a\
&#x20;               header of this name

### getLocalAddr()

Returns the Internet Protocol (IP) address of the interface on which the request was received.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the IP address on which the request was received.

### getLocalName()

Returns the host name of the Internet Protocol (IP) interface on which the request was received.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the host name of the IP on which the request was received.

### getLocalPort()

Returns the Internet Protocol (IP) port number of the interface on which the request was received.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) an integer specifying the port number

### getLocaleLanguageTag()

Returns the preferred `Locale` that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server. Returns a well-formed IETF BCP 47 language tag representing this locale.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the preferred `Locale` for the client

### getLocalesLanguageTags()

Returns an array of `Locale` objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an array containing one `Locale`, the default locale for the server. Returns well-formed IETF BCP 47 language tags representing the locales.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of preferred `Locale` objects for the client

### getMethod()

Returns the name of the HTTP method with which this\
request was made, for example, GET, POST, or PUT.\
Same as the value of the CGI variable REQUEST\_METHOD.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` specifying the name of the method with which this request was made

### getParameter(name)

Returns the value of a request parameter as a `String`, or `null` if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use #getParameterValues(String).

If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by `getParameterValues`.

If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via #getInputStream or #getReader can interfere with the execution of this method.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **name** a `String` specifying the name of the parameter

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` representing the single value of the parameter

### getParameterMap()

Returns an object of the parameters of this request.

Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) an object containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.

### getParameterNames()

Returns an array of `String` objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty array.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of `String` objects, each `String` containing the name of a request parameter; or an empty array if the request has no parameters

### getParameterValues(name)

Returns an array of `String` objects containing all of the values the given request parameter has, or `null` if the parameter does not exist.

If the parameter has a single value, the array has a length of 1.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **name** a `String` containing the name of the parameter whose value is requested

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of `String` objects containing the parameter's values

### getPathInfo()

Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character.

This method returns `null` if there was no extra path information.

Same as the value of the CGI variable PATH\_INFO.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String`, decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; or `null` if the URL does not have any extra path information

### getPathTranslated()

Returns any extra path information after the servlet name but before the query string, and translates it to a real path. Same as the value of the CGI variable PATH\_TRANSLATED.

If the URL does not have any extra path information, this method returns `null` or the servlet container cannot translate the virtual path to a real path for any reason (such as when the web application is executed from an archive). The web container does not decode this string.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` specifying the real path, or `null` if the URL does not have any extra path information

### getProtocol()

Returns the name and version of the protocol the request uses in the form *protocol/majorVersion.minorVersion*, for example, HTTP/1.1. For HTTP servlets, the value returned is the same as the value of the CGI variable `SERVER_PROTOCOL`.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the protocol name and version number

### getQueryString()

Returns the query string that is contained in the request URL after the path. This method returns `null` if the URL does not have a query string. Same as the value of the CGI variable QUERY\_STRING.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the query string or `null` if the URL contains no query string. The value is not decoded by the container.

### getRealPath(path)

Gets the *real* path corresponding to the given *virtual* path.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **path** the *virtual* path to be translated to a *real* path

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the *real* path, or \<tt>null\</tt> if the translation cannot be performed

### getRemoteAddr()

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable `REMOTE_ADDR`.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the IP address of the client that sent the request

### getRemoteHost()

Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address. For HTTP servlets, same as the value of the CGI variable `REMOTE_HOST`.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the fully qualified name of the client

### getRemotePort()

Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) an integer specifying the port number

### getRequestURI()

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example: \<table summary="Examples of Returned Values"> \<tr align=left>\<th>First line of HTTP request \</th> \<th> Returned Value\</th> \<tr>\<td>POST /some/path.html HTTP/1.1\<td>\<td>/some/path.html \<tr>\<td>GET <http://foo.bar/a.html> HTTP/1.0 \<td>\<td>/a.html \<tr>\<td>HEAD /xyz?a=b HTTP/1.1\<td>\<td>/xyz \</table>

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the part of the URL from the protocol name up to the query string

### getRequestURL()

Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

If this request has been forwarded using javax.servlet.RequestDispatcher#forward, the server path in the reconstructed URL must reflect the path used to obtain the RequestDispatcher, and not the server path specified by the client.

This method is useful for creating redirect messages and for reporting errors.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `StringBuffer` object containing the reconstructed URL

### getScheme()

Returns the name of the scheme used to make this request, for example, `http`, `https`, or `ftp`. Different schemes have different rules for constructing URLs, as noted in RFC 1738.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the name of the scheme used to make this request

### getServerName()

Returns the host name of the server to which the request was sent. It is the value of the part before ":" in the `Host` header value, if any, or the resolved server name, or the server IP address.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the name of the server

### getServerPort()

Returns the port number to which the request was sent. It is the value of the part after ":" in the `Host` header value, if any, or the server port where the client connection was accepted on.

**Returns:** [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) an integer specifying the port number

### getServletPath()

Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT\_NAME.

This method will return an empty string ("") if the servlet used to process this request was matched using the "/\*" pattern.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) a `String` containing the name or path of the servlet being called, as specified in the request URL, decoded, or an empty string if the servlet used to process the request is matched using the "/\*" pattern.

### isSecure()

Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) a boolean indicating if the request was made using a secure channel

***
