Type Guards
@opra/http exports four type guard functions for narrowing HTTP message types at runtime.
import {
isNodeIncomingMessage,
isHttpIncoming,
isNodeOutgoingMessage,
isHttpOutgoing,
} from '@opra/http';
isNodeIncomingMessage
isNodeIncomingMessage(v: any): v is NodeIncomingMessage
Returns true if v has a string method, an array rawHeaders, and is a Readable stream. Use to check for the low-level request interface before upgrading to HttpIncoming.
isHttpIncoming
isHttpIncoming(v: any): v is HttpIncoming
Returns true if v passes isNodeIncomingMessage and additionally exposes header(), acceptsLanguages(), and readBody(). Use to distinguish a fully-featured HttpIncoming from a bare NodeIncomingMessage.
isNodeOutgoingMessage
isNodeOutgoingMessage(v: any): v is NodeOutgoingMessage
Returns true if v has a getHeaders() method and is a stream. Use to check for the low-level response interface before upgrading to HttpOutgoing.
isHttpOutgoing
isHttpOutgoing(v: any): v is HttpOutgoing
Returns true if v passes isNodeOutgoingMessage and additionally exposes clearCookie() and cookie(). Use to distinguish a fully-featured HttpOutgoing from a bare NodeOutgoingMessage.