API: request
Source:
http/request.ts
The Request API under the HTTP module is responsible for managing standard HTTP request parameters, headers, cookies, and request metadata provided to server-side scripting services.
Usage
import { request, response } from "sdk/http";
let method = request.getMethod();
response.println("[Method]: " + method);
response.flush();
response.close();Classes
Request
Represents the HTTP Request object available within a service execution
context. It provides access to HTTP metadata, query parameters, request
body content, cookies, and security information.
All functions in this class are static: no instance of Request
needs to be created.
Methods
isValid
isValid ():booleanDetermines whether the current thread is handling a valid HTTP request.
@returnstrueif called in a valid HTTP request context, otherwisefalse.
getMethod
getMethod ():stringReturns the HTTP method (GET, POST, PUT, DELETE, etc.).
getRemoteUser
getRemoteUser ():stringReturns the authenticated remote user name if available.
getPathInfo
getPathInfo ():stringReturns the portion of the request path following the servlet path.
getPathTranslated
getPathTranslated ():stringReturns the translated file system path for the request.
getHeader
getHeader (name:string):stringReturns the value of a specific HTTP header.
@param name - Header name to retrieve.
@returns The header value orundefinedif not found.
isUserInRole
isUserInRole (role:string):booleanChecks whether the remote user has the given role.
@param role - The role name to check.
getAttribute
getAttribute (name:string):string|undefinedReturns a request attribute value previously associated with the request.
@param name - The attribute name.
@returns A string value orundefined.
getAuthType
getAuthType ():stringReturns the authentication type if known (BASIC, CLIENT_CERT, etc.).
getCookies
getCookies ():Cookie[]Returns all cookies sent with the request.
@returns An array of Cookie objects.
getAttributeNames
getAttributeNames ():string[]Returns all available request attribute names.
getCharacterEncoding
getCharacterEncoding ():stringReturns the character encoding used in the request body.
getContentLength
getContentLength ():numberReturns the size of the request body in bytes, if known.
getHeaders
getHeaders (name:string):string[]Returns all values of a specific header.
@param name - Header name to retrieve.
getContentType
getContentType ():stringReturns the MIME content type of the request body.
getBytes
getBytes ():any[]Returns the raw request body as a byte array.
getText
getText ()voidReturns the request body as text. This is computed once and cached.
json
json ():any}|undefinedReturns the request body parsed as JSON if valid.
@returns A JSON object orundefinedif parsing fails.
getJSON
getJSON ():any}|undefinedSame as json(); explicit form.
getParameter
getParameter (name:string):stringReturns a request parameter value.
getParameters
getParameters ():string[]}Returns a map of request parameters to arrays of values.
getResourcePath
getResourcePath ():stringReturns the allocated request resource path.
getHeaderNames
getHeaderNames ():string[]Returns all header names.
getParameterNames
getParameterNames ():string[]Returns all parameter names.
getParameterValues
getParameterValues (name:string):string[]Returns all values for a given parameter name.
getProtocol
getProtocol ():stringReturns the HTTP protocol version.
getScheme
getScheme ():stringReturns the transport scheme (e.g., http, https).
getContextPath
getContextPath ():stringReturns the context path of the request.
getServerName
getServerName ():stringReturns the server host name.
getServerPort
getServerPort ():numberReturns the server port number.
getQueryString
getQueryString ():stringReturns the full raw query string.
getQueryParametersMap
getQueryParametersMap ():string|string[]}Parses the query string and returns a map of parameter keys to values.
If the same key appears multiple times, values are collected into arrays.
getRemoteAddress
getRemoteAddress ():stringReturns the remote client IP address.
getRemoteHost
getRemoteHost ():stringReturns the remote client host name.
setAttribute
setAttribute (name:string, value:string):voidAssigns a new attribute to the request.
removeAttribute
removeAttribute (name:string):voidRemoves an attribute from the request.
getLocale
getLocale ():anyReturns the client locale preferences.
getRequestURI
getRequestURI ():stringReturns the full request URI.
isSecure
isSecure ():booleanReturns
trueif the request was made over HTTPS.
getRequestURL
getRequestURL ():stringReturns the full request URL including protocol and host.
getServicePath
getServicePath ():stringReturns the internal service path for routing.
getRemotePort
getRemotePort ():numberReturns the remote client port number.
getLocalName
getLocalName ():stringReturns the local network host name.
getLocalAddress
getLocalAddress ():stringReturns the local IP address.
getLocalPort
getLocalPort ():numberReturns the server local port number handling the request.
getInputStream
getInputStream ():InputStreamReturns the request body as a binary input stream.
Useful for processing binary uploads.