spirit
Version:
extensible web library for building applications & frameworks
122 lines (68 loc) • 2.88 kB
Markdown
Internal API
Considered stable unless denoted with "**".
NOTE: Unlike the rest of the spirit API, there are no camelCase variants.
- [is_Response](
- [size_of](
- [type_of **](
- [callp_response](
- [resolve_response](
-------------------------------------------
Returns `true` or `false` depending on if `v` is a instance of [Response](Response.md)
Does not return true for a response map, this is a specific check.
[](../../src/http/response-class.js
* v {*}
{boolean}
-------------------------------------------
Returns the size of `v` in bytes, utf-8 is assumed.
It only returns a size for a string or buffer. Otherwise it returns undefined.
This function is useful for determining the "Content-Length" of a response body that is a string or buffer.
[](../../src/http/utils.js
* v {string|buffer} A string or buffer to check
{number} The size of the `v` (string or buffer)
-------------------------------------------
** This function is expected to change in the future
Returns a string representation of the type of `v`. It is similar to `typeof` but it will also correctly detect and report types for: null, array, buffer, stream, file-stream.
As well as all types that `typeof` already identifies (undefined, string, number, etc.)
Example:
```js
type_of([1, 2, 3]) // "array"
type_of(new Buffer("hi")) // "buffer"
type_of(null) // "null"
```
[Source: src/http/utils.js (type_of)](../../src/http/utils.js#L18)
#### Arguments
* v {*} value or object to check
{string} A string representation of the type of `v`
-------------------------------------------
Works similarly to `spirit.callp`. Except it adds special handling when the function being called returns a response map _but with a response body that is a Promise_.
When this occurs, resolves the response's body first instead of passing along a Promise of a response map which has a Promise as it's body that may not be resolved yet.
Additionally it surpresses Promise warnings regarding async error handling.
This is mostly used internally.
[](../../src/core/promise_utils.js
* p {Promise}
{Promise}
-------------------------------------------
__REMOVED IN v0.6.0__
Resolves a response's body if it's a Promise.
This is mostly used internally.
* p {Promise}
{Promise}