Respect caller-provided User-Agent in Api.DownloadBytes#9458
Merged
Martin-Molinero merged 1 commit intoMay 6, 2026
Merged
Conversation
Skip setting the default "QCAlgorithm.Download(): User Agent Header" when the caller already supplied a User-Agent in the headers dictionary. The check uses HttpRequestHeaders.Contains, which matches header names case-insensitively per the HTTP spec. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jaredbroad
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Api.DownloadBytesalways set a defaultUser-Agentheader ("QCAlgorithm.Download(): User Agent Header") before applying caller-supplied headers. BecauseHttpRequestHeadersdeduplicates case-insensitively butTryAddWithoutValidationdoes not replace an existing header, a caller that passed their ownUser-Agent(in any casing) ended up sending the default value instead of the one they specified.The default is now applied only when the caller has not already supplied a
User-Agent. The check usesDefaultRequestHeaders.Contains("User-Agent"), which matches header names case-insensitively per the HTTP spec, souser-agent,User-Agent, andUSER-AGENTare all detected.Related Issue
N/A — small fix surfaced while reviewing
Api.DownloadBytes.Motivation and Context
Algorithms calling
QCAlgorithm.Download(...)with a customUser-Agent(e.g., to comply with a third-party API's UA policy) were silently overridden by the framework default, causing requests to be rejected or rate-limited by the remote endpoint.Requires Documentation Change
No.
How Has This Been Tested?
HttpRequestHeaders.Containssemantics (case-insensitive header-name match).headersisnullor has no UA, the default UA is added.headerscontains aUser-Agent(any casing), the default is skipped and the caller's value is sent.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>