new HttpResponse()
A HTTP response
Extends
Members
(static) BAD_REQUEST
Status code 400 Bad Request
(static) INTERNAL_SERVER_ERROR
Status code 500 Internal Server Error
(static) NOT_FOUND
Status code 404 Not Found
(static) NOT_MODIFIED
Status code 304 Not Modified
(static) OK
Status code 200 OK
(static) UNAUTHORIZED
Status code 401 Unauthorized
Methods
attach(attachment)
Attach a entity
Name | Type | Description |
---|---|---|
attachment | $k.NetEntity |
- Inherited From
If the entity is not a valid attachment
attachments() → {Array.<$k.NetEntity>}
Returns the attached entities
- Inherited From
- Type:
- Array.<$k.NetEntity>
base64String() → {string}
Get the binay contents as base64-encoded string. Returns undefined if the contents is not binary
- Inherited From
- Type:
- string
charset() → {string}
Returns the charset
- Inherited From
- Type:
- string
code() → {number}
Returns the status code of the response
- Type:
- number
contentDisposition() → {string}
Returns the content disposition
- Inherited From
- Type:
- string
contentLength() → {number}
Returns the content length
- Inherited From
- Type:
- number
contentType() → {string}
Returns the content type (only the media type part)
- Inherited From
- Type:
- string
dataUrl() → {string}
Returns the entity bytes as a data URL, or undefined if the entity is not binary
- Inherited From
- Type:
- string
debugString() → {string}
Prints the entity, except binary contents, for debugging purposes
- Inherited From
- Type:
- string
filename() → {string}
Returns the filename part of the content disposition field
- Inherited From
- Type:
- string
formData() → {object}
Get all form fields (multipart/form-data or application/x-www-form-urlencoded). The property names correspond to the field names. The property values are either strings (if the form is of type application/x-www-form-urlencoded) or NetEntities (multipart/form-data)
- Inherited From
- See
- Type:
- object
headerField(fieldName) → {string}
Get the value of the field of the request header. Returns undefined if the field does not exist
Name | Type | Description |
---|---|---|
fieldName | string |
- Inherited From
The field value
- Type:
- string
headerFields() → {object}
Get all fields of the request header. Field names are always lower case
- Inherited From
- Type:
- object
isBinary() → {boolean}
True if the entity has binary contents
- Inherited From
- Type:
- boolean
isSuccess() → {boolean}
Returns true if the code indicates a successful response (2xx), false otherwise
- Type:
- boolean
removeHeaderField(fieldName)
Removes the field of the request heade
Name | Type | Description |
---|---|---|
fieldName | string |
- Since
- 5.0.3
- Inherited From
setCharset(charset)
Set the charset
Name | Type | Description |
---|---|---|
charset | string |
- Inherited From
If the charset is unknown
setCode(code)
Set the status code of the response
Name | Type | Description |
---|---|---|
code | number |
If the code is not a valid HTTP status code
setCodeBadRequest()
Set the status code of the response to 400 (Bad request). Equivalent to setCode($k.HttpResponse.BAD_REQUEST)
setCodeNotFound()
Set the status code of the response to 404 (Not found). Equivalent to setCode($k.HttpResponse.NOT_FOUND)
setCodeNotModified()
Set the status code of the response to 304 (Not Modified). Equivalent to setCode($k.HttpResponse.NOT_MODIFIED)
setCodeOk()
Set the status code of the response to 200 (Ok). Equivalent to setCode($k.HttpResponse.OK)
setCodeUnauthorized()
Set the status code of the response to 401 (Unauthorized). Equivalent to setCode($k.HttpResponse.UNAUTHORIZED)
setContentDisposition(contentDisposition)
Set the content disposition
Name | Type | Description |
---|---|---|
contentDisposition | string |
- Inherited From
setContentLength(length)
Set the content length
Name | Type | Description |
---|---|---|
length | number |
- Inherited From
setContents(contents)
Set the contents of the entity. Also sets the content type and filename if known. The contents object can be a string, document ($k.TextDocument), a blob value ($k.Blob) or another NetEntity
Name | Type | Description |
---|---|---|
contents | Contents object |
- Inherited From
setContentType(mediaType, charsetopt)
Set the content type
Name | Type | Attributes | Description |
---|---|---|---|
mediaType | string | Media type of the contents | |
charset | string | <optional> | Charset of the contents |
- Inherited From
setCookie(cookie)
Add the cookie to the response, instructing the client to set the cookie
Name | Type | Description |
---|---|---|
cookie | $k.NewCookie | The new cookie |
If the cookie is not a valid new cookie
setFilename(filename)
Set the filename part of the content disposition field
Name | Type | Description |
---|---|---|
filename | string |
- Inherited From
setHeaderField(fieldName, fieldValue)
Set the value of the field of the request header
Name | Type | Description |
---|---|---|
fieldName | string | |
fieldValue |
- Inherited From
If the value does not match the type of the field
setText(text)
Set the text as the body
Name | Type | Description |
---|---|---|
text | string |
- Inherited From
text(charsetopt) → {string}
Get the contents as string
Name | Type | Attributes | Description |
---|---|---|---|
charset | string | <optional> | Charset of the characters. Required for binary entities. Optional for text entities. |
- Inherited From
- Type:
- string