Skip to content

Commit

Permalink
fix: request/response object validation (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP authored Jan 10, 2020
1 parent 5881e45 commit f6f8256
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/protocol-http/src/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class HttpRequest implements HttpMessage, Endpoint {

static isInstance(request: unknown): request is HttpRequest {
//determine if request is a valid httpRequest
if (!request) return false;
const req: any = request;
return (
"method" in req &&
Expand Down
8 changes: 5 additions & 3 deletions packages/protocol-http/src/httpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ export class HttpResponse {
public statusCode: number;
public headers: HeaderBag;
public body?: any;
private readonly isHttpResponse = true;

constructor(options: HttpResponseOptions) {
this.statusCode = options.statusCode;
this.headers = options.headers || {};
this.body = options.body;
}

static isInstance(request: unknown): request is HttpResponse {
static isInstance(response: unknown): response is HttpResponse {
//determine if response is a valid HttpResponse
if (!response) return false;
const resp = response as any;
return (
request !== undefined && (request as HttpResponse).isHttpResponse === true
typeof resp.statusCode === "number" && typeof resp.headers === "object"
);
}
}

0 comments on commit f6f8256

Please sign in to comment.