Skip to content

Send the CSOM User-Agent header once - #1302

Merged
YifengMao merged 1 commit into
pnp:devfrom
kola-tm:fix-duplicate-user-agent
Oct 27, 2026
Merged

YifengMao merged 1 commit into
pnp:devfrom
kola-tm:fix-duplicate-user-agent

Conversation

@kola-tm

@kola-tm kola-tm commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Send the CSOM User-Agent header once

Fixes #1301

CSOM requests sent through HttpClientWebRequestExecutorFactory carry the User-Agent value twice:

User-Agent: ISV|Contoso|App/1.0 ISV|Contoso|App/1.0

Microsoft's throttling guidance asks applications to send a single ISV|Company|App/Version value. A doubled value may not count as decorated traffic.

Cause

HttpClientSPWebRequestExecutor.ExecuteImplementation copies every header from HttpWebRequest.Headers, and then adds HttpWebRequest.UserAgent again with ParseAdd. HttpWebRequest.UserAgent is stored in Headers, so the loop already copies it.

Changes

  • Remove the separate ParseAdd of User-Agent in HttpClientSPWebRequestExecutor.ExecuteImplementation. Headers.Add in the copy loop uses the same parser and throws the same FormatException on an invalid value.
  • Add Isolated/Http/HttpClientWebRequestExecutorFactoryTests. It sends a request through the factory with a capturing HttpMessageHandler, and asserts that User-Agent appears once and that other request headers are still copied. It needs no tenant.

HttpWebRequest keeps UserAgent inside its Headers collection, so the header copy loop in HttpClientSPWebRequestExecutor already moves it onto the HttpRequestMessage. The separate ParseAdd then appended the same value a second time, and every CSOM request sent through HttpClientWebRequestExecutorFactory carried a doubled User-Agent. Microsoft's throttling guidance expects a single ISV|Company|App/Version value, so a doubled value may not count as decorated traffic.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@YifengMao YifengMao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed: removes the duplicate User-Agent insertion and adds a focused regression test.

@YifengMao
YifengMao merged commit a69a5b9 into pnp:dev Oct 27, 2026
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.

HttpClientSPWebRequestExecutor sends the User-Agent header twice

2 participants