Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol-http): request/response object validation #709

Merged
merged 1 commit into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
);
}
}