Followup refactoring to #62
The code is still quite messy. Needs a refactoring (should be a separate PR) - the context.response is expected to be IncomingMessage, however that isn't right with Got ideology. Got wraps parts of ClientRequest and IncomingMessage into Got's Request. For example, in order to access the original IncomingMessage, you need request.response. So, in order to get the headers, request.response.headers.
To solve this, there has been added addResponsePropertiesToStream which turns Got's Request instance to look like IncomingMessage, overwriting some properties along the way. Oh, and it gets casted from Request to IncomingMessage (which is extremely confusing).
The way to access response-related properties in Got may change in the future, e.g.:
const { statusCode, headers, socket, stream } = await got.stream(...);
but this is just an idea.
Originally posted by @szmarczak in https://github.com/apify/apify-ts/issues/62#issuecomment-1087085537
From Slack:
https://github.com/apify/apify-ts/blob/b7a41eec03e0a2718503b3ea29c6e2ac57edf6d5/packages/cheerio-crawler/src/internals/cheerio-crawler.ts#L1127-L1155 this converts Got's Request to IncomingMessage-like.
which is used in https://github.com/apify/apify-ts/blob/b7a41eec03e0a2718503b3ea29c6e2ac57edf6d5/packages/cheerio-crawler/src/internals/cheerio-crawler.ts#L1058
=> https://github.com/apify/apify-ts/blob/b7a41eec03e0a2718503b3ea29c6e2ac57edf6d5/packages/cheerio-crawler/src/internals/cheerio-crawler.ts#L848 => https://github.com/apify/apify-ts/blob/b7a41eec03e0a2718503b3ea29c6e2ac57edf6d5/packages/cheerio-crawler/src/internals/cheerio-crawler.ts#L806-L810
so maybe we could replace this response with something like:
response: {
stream: Request,
headers,
statusCode,
ip,
socket,
}