Skip to content

feat: add AbortSignal and rename timeouttimeoutMillis in SendRequestOptions#3457

Open
Copilot wants to merge 4 commits intov4from
copilot/add-abortsignal-option-basehttpclient
Open

feat: add AbortSignal and rename timeouttimeoutMillis in SendRequestOptions#3457
Copilot wants to merge 4 commits intov4from
copilot/add-abortsignal-option-basehttpclient

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

SendRequestOptions lacked an AbortSignal option, preventing users from passing custom cancellation signals to BaseHttpClient. The timeout field also didn't follow the repo convention of using timeoutMillis.

Changes

  • @crawlee/typesSendRequestOptions: renamed timeouttimeoutMillis, added signal?: AbortSignal
  • @crawlee/http-clientBaseHttpClient: updated to use timeoutMillis; when both signal and timeoutMillis are provided, combines them via AbortSignal.any()
  • @crawlee/basic-crawler, @crawlee/http-crawler, @crawlee/utils — updated all call sites to use timeoutMillis
  • test/core/base-http-client.test.ts — added tests covering custom signal propagation, signal + timeoutMillis combination, and timeout-based abort

Usage

const response = await httpClient.sendRequest(request, {
    timeoutMillis: 10_000,
    signal: myAbortController.signal,
});

When both are supplied, the request is aborted on whichever fires first.

Original prompt

This section details on the original issue you should resolve

<issue_title>v4: add AbortSignal option to the BaseHttpClient interface</issue_title>
<issue_description>Adding AbortSignal option to the BaseHttpClient interface would allow users to pass their custom signal to the HttpClient (alongside the timeout, which should be renamed to timeoutMillis to follow the best practices in this repo).</issue_description>

<agent_instructions>Make minimal changes to achieve the goal described in the issue. do not add excessive comments (but add TSdocs for public interfaces you add). use conventional commits for commit messages and PR title.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 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.

…endRequestOptions

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add AbortSignal option to BaseHttpClient interface feat: add AbortSignal and rename timeouttimeoutMillis in SendRequestOptions Feb 27, 2026
@barjin barjin requested a review from Copilot February 27, 2026 15:31
@barjin barjin marked this pull request as ready for review February 27, 2026 15:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?: AbortSignal field to SendRequestOptions interface with TSDoc
  • Renamed timeouttimeoutMillis in SendRequestOptions to follow the established Millis suffix 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/utils to 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 timeouttimeoutMillis 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;
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new signal parameter in SendRequestOptions lacks test coverage. Consider adding tests to verify:

  1. That a custom AbortSignal is properly propagated to the fetch call
  2. That when both signal and timeoutMillis are provided, the request is aborted when either fires
  3. That cancelling a custom signal properly aborts the request

These tests would help ensure the AbortSignal.any() combination logic works correctly.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 5 self-contained tests in test/core/base-http-client.test.ts (commit 7751403):

  1. Basic request works without any signal/timeout
  2. Aborts when a pre-aborted signal is passed
  3. Aborts when the signal is aborted after the request starts
  4. Aborts when timeoutMillis elapses
  5. Aborts when both signal and timeoutMillis are provided and the signal fires first

Copilot AI and others added 2 commits February 27, 2026 15:51
…Client

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
…ndRequestOptions`

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants