feat: add AbortSignal and rename timeout → timeoutMillis in SendRequestOptions#3457
feat: add AbortSignal and rename timeout → timeoutMillis in SendRequestOptions#3457
AbortSignal and rename timeout → timeoutMillis in SendRequestOptions#3457Conversation
…endRequestOptions Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
AbortSignal and rename timeout → timeoutMillis in SendRequestOptions
There was a problem hiding this comment.
Pull request overview
This pull request adds support for custom AbortSignal cancellation to the HTTP client layer and renames the timeout parameter to timeoutMillis to align with the repository's established naming conventions. The changes address the lack of a mechanism for users to pass custom cancellation signals to BaseHttpClient, while also improving consistency across the codebase.
Changes:
- Added
signal?: AbortSignalfield toSendRequestOptionsinterface with TSDoc - Renamed
timeout→timeoutMillisinSendRequestOptionsto follow the establishedMillissuffix convention used throughout the codebase - Implemented
AbortSignal.any()to combine custom signals and timeout-based signals, ensuring requests abort on whichever fires first - Updated all call sites across
@crawlee/basic-crawler,@crawlee/http-crawler, and@crawlee/utilsto use the new parameter name
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/types/src/http-client.ts | Added signal field and renamed timeout → timeoutMillis in SendRequestOptions interface with documentation |
| packages/http-client/src/base-http-client.ts | Updated createAbortSignal to accept and combine both signal and timeout; refactored resolveRequestContext to return signal instead of timeout |
| packages/basic-crawler/src/internals/send-request.ts | Updated to pass both timeoutMillis and signal from override options |
| packages/http-crawler/src/internals/http-crawler.ts | Updated call site to use timeoutMillis parameter name |
| packages/utils/src/internals/sitemap.ts | Updated call site to use timeoutMillis parameter name |
| packages/utils/test/mock-http-client.ts | Updated mock implementation to use timeoutMillis parameter name |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** Timeout for the HTTP request in milliseconds. */ | ||
| timeoutMillis?: number; | ||
| /** An AbortSignal to cancel the HTTP request. */ | ||
| signal?: AbortSignal; |
There was a problem hiding this comment.
The new signal parameter in SendRequestOptions lacks test coverage. Consider adding tests to verify:
- That a custom AbortSignal is properly propagated to the fetch call
- That when both
signalandtimeoutMillisare provided, the request is aborted when either fires - That cancelling a custom signal properly aborts the request
These tests would help ensure the AbortSignal.any() combination logic works correctly.
There was a problem hiding this comment.
@copilot apply changes based on this feedback. Add small, self-contained tests that match the rest of the other tests in style and quality. Do not add too many, 3-5 is enough.
There was a problem hiding this comment.
Added 5 self-contained tests in test/core/base-http-client.test.ts (commit 7751403):
- Basic request works without any signal/timeout
- Aborts when a pre-aborted signal is passed
- Aborts when the signal is aborted after the request starts
- Aborts when
timeoutMilliselapses - Aborts when both
signalandtimeoutMillisare provided and the signal fires first
…Client Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
…ndRequestOptions` Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
SendRequestOptionslacked anAbortSignaloption, preventing users from passing custom cancellation signals toBaseHttpClient. Thetimeoutfield also didn't follow the repo convention of usingtimeoutMillis.Changes
@crawlee/types—SendRequestOptions: renamedtimeout→timeoutMillis, addedsignal?: AbortSignal@crawlee/http-client—BaseHttpClient: updated to usetimeoutMillis; when bothsignalandtimeoutMillisare provided, combines them viaAbortSignal.any()@crawlee/basic-crawler,@crawlee/http-crawler,@crawlee/utils— updated all call sites to usetimeoutMillistest/core/base-http-client.test.ts— added tests covering custom signal propagation, signal + timeoutMillis combination, and timeout-based abortUsage
When both are supplied, the request is aborted on whichever fires first.
Original prompt
AbortSignaloption to theBaseHttpClientinterface #3456💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.