Comparing version 0.1.1 to 0.1.2
@@ -20,4 +20,5 @@ import { Readable } from 'stream'; | ||
request: Request; | ||
headers?: HeadersObject; | ||
name: string; | ||
constructor(message: string, code: string, status: number, request: Request, original?: Error); | ||
constructor(message: string, code: string, status: number, request: Request, cause?: Error, headers?: HeadersObject); | ||
} | ||
@@ -115,3 +116,3 @@ /** | ||
method: string; | ||
error(message: string, code: string, status?: number, original?: Error): HttpError; | ||
error(message: string, code: string, status?: number, original?: Error, headers?: HeadersObject): HttpError; | ||
abort(): boolean; | ||
@@ -118,0 +119,0 @@ setTimeout(ms: number): void; |
@@ -51,4 +51,4 @@ "use strict"; | ||
__extends(HttpError, _super); | ||
function HttpError(message, code, status, request, original) { | ||
var _this = _super.call(this, message, original) || this; | ||
function HttpError(message, code, status, request, cause, headers) { | ||
var _this = _super.call(this, message, cause) || this; | ||
_this.name = 'HttpError'; | ||
@@ -58,2 +58,3 @@ _this.code = code; | ||
_this.request = request; | ||
_this.headers = headers; | ||
return _this; | ||
@@ -113,3 +114,3 @@ } | ||
if (item != null) { | ||
this.raw.push(name, item); | ||
this.raw.push(name, String(item)); | ||
} | ||
@@ -280,2 +281,3 @@ } | ||
this.length = Buffer.byteLength(str); | ||
return; | ||
} | ||
@@ -459,5 +461,5 @@ throw new TypeError("Unknown body: " + body); | ||
}); | ||
Request.prototype.error = function (message, code, status, original) { | ||
Request.prototype.error = function (message, code, status, original, headers) { | ||
if (status === void 0) { status = 500; } | ||
return new HttpError(message, code, status, this, original); | ||
return new HttpError(message, code, status, this, original, headers); | ||
}; | ||
@@ -509,2 +511,4 @@ Request.prototype.abort = function () { | ||
_this.statusText = options.statusText; | ||
// Emit a response event to listeners. | ||
_this.request.events.emit('response', _this); | ||
return _this; | ||
@@ -515,3 +519,3 @@ } | ||
return this._setTimeout(function () { | ||
_this.events.emit('error', _this.request.error('Response timeout', 'ETIMEOUT', 408)); | ||
_this.request.events.emit('error', _this.request.error('Response timeout', 'ETIMEOUT', 408)); | ||
_this.request.abort(); | ||
@@ -518,0 +522,0 @@ }, ms); |
@@ -25,2 +25,8 @@ "use strict"; | ||
}); | ||
it('should json encode body if a simple object', function () { | ||
var req = new index_1.Request({ url: '/json' }); | ||
var res = new index_1.Response(req, { body: { foo: 'bar' } }); | ||
expect(res.headers.get('Content-Type')).toBe('application/json'); | ||
expect(res.body).toEqual('{\"foo\":\"bar\"}'); | ||
}); | ||
}); | ||
@@ -27,0 +33,0 @@ describe('cloning', function () { |
{ | ||
"name": "servie", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Standard HTTP interfaces", | ||
@@ -47,3 +47,3 @@ "main": "dist/index.js", | ||
"tslint": "^4.3.1", | ||
"tslint-config-standard": "^2.0.0", | ||
"tslint-config-standard": "^3.0.0", | ||
"typescript": "^2.1.5", | ||
@@ -50,0 +50,0 @@ "typings": "^2.1.0" |
@@ -18,6 +18,9 @@ # ![Servie](https://cdn.rawgit.com/blakeembrey/node-servie/master/logo.svg) | ||
* [`throwback`](https://github.com/blakeembrey/throwback) Compose middleware into a single function | ||
* [`servie-lambda`](https://github.com/blakeembrey/node-servie-lambda) Transport layer for AWS Lambda | ||
* [`throwback`](https://github.com/blakeembrey/throwback) Compose middleware functions into a single function | ||
* [`servie-lambda`](https://github.com/blakeembrey/node-servie-lambda) Servie transport layer for AWS Lambda | ||
* [`busboy`](https://www.npmjs.com/package/busboy) A streaming parser for HTML form data | ||
* [`qs`](https://github.com/ljharb/qs) and [`querystring`](https://nodejs.org/api/querystring.html) Parse the HTTP query string to an object | ||
* [`consolidate`](https://github.com/tj/consolidate.js) Template rendering | ||
### Common | ||
### `Common` | ||
@@ -62,3 +65,2 @@ > Base HTTP class for common request and response logic. | ||
* `trailers` Emitted when the `trailers` object becomes available | ||
* `error` Emitted when an out-of-band error occurs (e.g. abort or timeout) and MUST be handled by the transport | ||
* `started` Emitted when the request/response has started | ||
@@ -68,3 +70,3 @@ * `finished` Emitted when the request/respone has finished | ||
### Request | ||
### `Request` | ||
@@ -107,4 +109,5 @@ > HTTP class for encapsulating a `Request`, extends `Common`. | ||
* `abort` Emitted when the request is aborted and MUST be handled by transport | ||
* `error` Emitted when an out-of-band error occurs (e.g. abort or timeout) and MUST be handled by the transport | ||
### Response | ||
### `Response` | ||
@@ -133,3 +136,3 @@ > HTTP class for encapsulating a `Response`, extends `Common`. | ||
### Headers | ||
### `Headers` | ||
@@ -156,3 +159,3 @@ > Used by `Common` for `Request` and `Response` objects. | ||
### HTTP Error | ||
### `HttpError` | ||
@@ -159,0 +162,0 @@ > Internally and externally triggered HTTP errors. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75475
779
186