Type Guards
@opra/http exports four type guard functions for narrowing HTTP message types at runtime.
import {
isHttpIncomingMessage,
isHttpRequest,
isHttpOutgoingMessage,
isHttpResponse,
} from '@opra/http';
isHttpIncomingMessage
isHttpIncomingMessage(v: any): v is http.IncomingMessage
Returns true if v is an instance of Node.js http.IncomingMessage. Use to check for the low-level request object before upgrading to HttpRequest.
isHttpRequest
isHttpRequest(v: any): v is HttpRequest
Returns true if v passes isHttpIncomingMessage and additionally exposes header(), acceptsLanguages(), and readBody(). Use to distinguish a fully-featured HttpRequest from a bare http.IncomingMessage.
isHttpOutgoingMessage
isHttpOutgoingMessage(v: any): v is http.OutgoingMessage
Returns true if v has a getHeaders() method and is a stream. Use to check for the low-level response object before upgrading to HttpResponse.
isHttpResponse
isHttpResponse(v: any): v is HttpResponse
Returns true if v passes isHttpOutgoingMessage and additionally exposes clearCookie() and cookie(). Use to distinguish a fully-featured HttpResponse from a bare http.OutgoingMessage.